标签:枚举进程
把APP完整路径传进去,枚举进程,通过简单的比较,就可以得到结果了。附上完整代码:
bool CheckApp(wstring _strGamePath)
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return false;
}
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
CloseHandle( hProcessSnap ); // clean the snapshot object
return false;
}
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
dwPriorityClass = 0;
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
TCHAR szPathBuf[MAX_PATH];
if( hProcess == NULL )
{
// return false;
}
else
{
GetModuleFileNameEx((HMODULE)hProcess,NULL,szPathBuf,MAX_PATH);
if (lstrcmpi(szPathBuf,_strGamePath.data())==0)
{
CloseHandle( hProcess );
CloseHandle( hProcessSnap );
return true;
}
CloseHandle( hProcess );
}
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return false;
}
标签:枚举进程
原文地址:http://blog.csdn.net/nanjian011/article/details/42871561