我从进程中获取可执行文件的路径时遇到问题。我正在使用Windoxs XP 64位与Python 2.7.5 x86_64,代码是:
pbi = create_string_buffer(200)
size = c_int()
NTDLL.NtQueryInformationProcess.restype = c_int
ret = NTDLL.NtQueryInformationProcess(h_process, #previously defined
27,
byref(pbi),
sizeof(pbi),
byref(size))
fbuf = pbi.raw[8:]
fbuf = fbuf[:fbuf.find('\0\0')+1]
return fbuf.decode('utf16', errors="ignore")
这项工作在Windows XP 32位上。在MSDN中创建,我找到了一个使用'psapi.dll'和特别是GetProcessImageFileName的传出机制。此方法适用于Windows 7 x64,代码为:
PSAPI = ctypes.WinDLL('Psapi.dll')
GetProcessImageFileName = PSAPI.GetProcessImageFileNameA
GetProcessImageFileName.restype = ctypes.wintypes.DWORD
path = create_string_buffer(200)
ret = GetProcessImageFileName(self.h_process, path, 200)
有人有任何想法????
提前致谢