请问哪个API能够通过ProcessID获得可知性文件的路径名?(200分)

  • 主题发起人 主题发起人 santgan
  • 开始时间 开始时间
S

santgan

Unregistered / Unconfirmed
GUEST, unregistred user!
3x very much
 
GetModuleFileName() ???
 
可执行文件?
 
The GetModuleFileName function retrieves the full path and filename for the <br>executable file containing the specified module. <br><br>Windows 95: The GetModuleFilename function will return long filenames when an <br>application's version number is greater than or equal to 4.00 and the long <br>filename is available. Otherwise, it returns only 8.3 format filenames.<br><br>DWORD GetModuleFileName(<br>&nbsp; &nbsp; HMODULE hModule, // handle to module to find filename for <br>&nbsp; &nbsp; LPTSTR lpFilename, // pointer to buffer for module path <br>&nbsp; &nbsp; DWORD nSize // size of buffer, in characters <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>hModule<br><br>Identifies the module whose executable filename is being requested. If this <br>parameter is NULL, GetModuleFileName returns the path for the file used to <br>create the calling process. <br><br>lpFilename<br><br>Points to a buffer that is filled in with the path and filename of the given <br>module. <br><br>nSize<br><br>Specifies the length, in characters, of the lpFilename buffer. If the length o<br>f the path and filename exceeds this limit, the string is truncated. <br><br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value is the length, in characters, of <br>the string copied to the buffer.<br>If the function fails, the return value is zero. To get extended error <br>information, call GetLastError. <br><br>Remarks<br><br>If a module is loaded in two processes, its module filename in one process may <br>differ in case from its module filename in the other process.<br><br>
 
可以自己看看这个例子:<br><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><br>
 
re tseug:<br>这个API我用过了,在Win2000下一直返回NULL,而且我通过任务列表确认我的调用<br>参数中ProcessID是正确的。
 
我的那个不行么?
 
TLHelp32只能在win9X中使用,在2000/XP下对应的是PSAPI,相应的信息,请查询DELPHI5开发人员<br>指南,其中有详细的注释
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部