现在的位置: 首页 > 综合 > 正文

获取进程列表

2013年12月19日 ⁄ 综合 ⁄ 共 1013字 ⁄ 字号 评论关闭

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 );
}

抱歉!评论已关闭.