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 获取安卓机器码

Delphi 删除或清除tstringgrid中的行

Delphi二进制字符串转换成中文字符串

Delphi静态和动态调用dll的实例

Delphi2010读取mysql数据库text类型乱码的解决方案

Delphi 比较俩组ip地址是否一样

Delphi 判断图像格式bmp jpg gif pcx png psd ras sgi tiff err

Delphi判断文件是否正在被使用

Delphi tms web core 从js调用pascal函数

Delphi fastreport快速入门

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



打赏

取消

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

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

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

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

评论

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