DWORD aProcesses[1024], dwSize, dwSize2;
char szProcessName[MAX_PATH] = "unknown";
char MyProcessName[MAX_PATH] = "Test.exe";//用实际文件名代替
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &dwSize ) )
return FALSE;
dwSize2 = dwSize / sizeof(DWORD);
for ( i = 0; i < dwSize2; i++ )
{
//取得进程的句柄 具体参见msdn
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, aProcesses[i] );
//取得进程名称
if ( hProcess )
{
HMODULE hMod;
DWORD dwSize;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&dwSize) )
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if (strcmp(szProcessName,MyProcessName))
{
CurProID = aProcesses[i];
break;
}
}
CloseHandle( hProcess );
}
char szProcessName[MAX_PATH] = "unknown";
char MyProcessName[MAX_PATH] = "Test.exe";//用实际文件名代替
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &dwSize ) )
return FALSE;
dwSize2 = dwSize / sizeof(DWORD);
for ( i = 0; i < dwSize2; i++ )
{
//取得进程的句柄 具体参见msdn
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, aProcesses[i] );
//取得进程名称
if ( hProcess )
{
HMODULE hMod;
DWORD dwSize;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&dwSize) )
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if (strcmp(szProcessName,MyProcessName))
{
CurProID = aProcesses[i];
break;
}
}
CloseHandle( hProcess );
}