win7(64位)下,无法通过OpenProcess和GetModuleFileNameEx得到进程的全路径
(2012-08-09 02:48:25)
标签:
杂谈 |
分类: windows |
CreateToolhelp32Snapshot不适用64位进城。
MSDN原文:
th32ProcessID
Ifthe specified process is a 64-bit process and the caller is a 32-bit process, this function fails and the last error code is ERROR_PARTIAL_COPY (299).
用EnumProcesses取得进城ID,然后调用上面的GetProcessPath(...)
以下是EnumProcesses的MSDN Sample Code,很简单,翻译一下就行。
#include<windows.h>
#include<stdio.h>
#include<tchar.h>
#include<psapi.h>
voidPrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
// Print the process name and identifier.
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
CloseHandle( hProcess );
}
voidmain( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
if( aProcesses[i] != 0 )
PrintProcessNameAndID( aProcesses[i] );
}
---------------------------------------------
MSDN原文:
th32ProcessID
If
用EnumProcesses取得进城ID,然后调用上面的GetProcessPath(...)
以下是EnumProcesses的
#include
#include
#include
#include
void
{
}
void
{
}
---------------------------------------------
前一篇:za 7 za 8

加载中…