通过进程id或者窗口标题怎么得到程序的路径?(50分)

  • 主题发起人 主题发起人 ailine
  • 开始时间 开始时间
A

ailine

Unregistered / Unconfirmed
GUEST, unregistred user!
如题!!!
 
这是通过窗体的句柄得到程序名的代码,但是只在9X底下有用,NT不行。<br>别忘了在 uses 部分加上TLHelp32单元<br>function GetAppName(const AWindowHandle: THandle): string;<br>var<br>&nbsp; PI: DWORD;<br>&nbsp; ContinueLoop:BOOL;<br>&nbsp; SnapshotHandle:THandle;<br>&nbsp; ProcessEntry32:TProcessEntry32;<br>begin<br>&nbsp; Result := '';<br>&nbsp; GetWindowThreadProcessId(AWindowHandle, @PI);<br><br>&nbsp; SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>&nbsp; ProcessEntry32.dwSize := Sizeof(ProcessEntry32);<br>&nbsp; ContinueLoop := Process32First(SnapshotHandle,ProcessEntry32);<br>&nbsp; while ContinueLoop do<br>&nbsp; begin<br>&nbsp; &nbsp; if ProcessEntry32.th32ProcessID = PI then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := ProcessEntry32.szExeFile;<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ContinueLoop:=Process32Next(SnapshotHandle, ProcessEntry32);<br>&nbsp; end;<br>&nbsp; CloseHandle(SnapshotHandle);<br>end;<br>
 
接受答案了.
 
后退
顶部