delphi 根据进程名得到进程所在路径


本文整理自网络,侵删。

 uses 
TlHelp32,psapi;
function GetPathFileofModule(ModuleName:String):String;
var
hProcSnap: THandle;
pProcess: THandle;
pe32: TProcessEntry32;
s: string;
buf:array[0..MAX_PATH] of char;
hMod:HMODULE;
cbNeeded:DWORD;
begin
hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
if hProcSnap = INVALID_HANDLE_VALUE then Exit;
pe32.dwSize := SizeOf(ProcessEntry32);
if Process32First(hProcSnap, pe32) = True then
while Process32Next(hProcSnap, pe32) = True do
begin
if uppercase(pe32.szExeFile)=uppercase(ModuleName) then
begin
pProcess:=OpenProcess(PROCESS_QUERY_INFORMATION or
PROCESS_VM_READ,
FALSE,
pe32.th32ProcessID);
if pProcess<>0 then
begin
if EnumProcessModules( pProcess,@hMod,sizeof(hMod),cbNeeded) then
begin
ZeroMemory(@buf,MAX_PATH+1);
GetModuleFileNameEx(pProcess, hMod,buf,MAX_PATH+1);
Result:=strpas(buf);
end;
end;
end;
end;
CloseHandle(hProcSnap);
end;
------------------------------------
调用方法:
ShowMessage(GetPathFileofModule('program.exe'));
//www.delphitop.com 搜集整理

相关阅读 >>

Delphi中模拟鼠标点击事件

Delphixe4 版本中,已针对移动平台 引入了 arc 模型

Delphi通过idhttp和php交互

正则表达式初学入门

Delphi 两种登录界面验证写法

Delphi删除目录及子目录及所有目录下的文件

Delphi 判断字符串是否是单词

Delphi 解析系统环境变量

Delphi firemonkey 学习笔记 �c tpopup 控件的使用

Delphi 获取与设置系统环境变量

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...