您的位置:首页 > 其它

获取进程列表

2009-08-24 17:37 513 查看
BOOL GetProcessList( )
{
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 )
{
printError( _T("CreateToolhelp32Snapshot (of processes)") );
return( FALSE );
}

// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );

// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
printError( _T("Process32First") ); // Show cause of failure
CloseHandle( hProcessSnap ); // Must clean up the
// snapshot object!
return( FALSE );
}

// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
printf( "\n\n"
"=====================================================" );
wprintf( _T("\nPROCESS NAME: %s"), pe32.szExeFile );
printf( "\n"
"-----------------------------------------------------" );

} while( Process32Next( hProcessSnap, &pe32 ) );

CloseHandle( hProcessSnap );
return( TRUE );
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: