RSS订阅 | 匿名投稿
您的位置:网站首页 > 进程 > 正文

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

作者:admin 来源:未知 日期:2010/5/22 2:13:59 人气: 标签:

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 搜集整理
读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: