Test Code/C++

WinApi - 사용중인 프로세스 조회

yaks101 2013. 12. 21. 01:29

사용중인 프로세스 조회


- 파일명 : Process_Test.cpp

- 컴파일 : g++ -Wall -o Process_Test.exe Process_Test.cpp




#include <windows.h>

#include <string.h>

#include <tlhelp32.h>

#include <iostream>


using namespace std;


void DisplayProcesses();


int main()

{

DisplayProcesses();

return 0;

}


void DisplayProcesses()

{

HANDLE hProc;


hProc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if( (int)hProc != -1 )

{

PROCESSENTRY32 entry ={0,};

entry.dwSize = sizeof(PROCESSENTRY32);

BOOL bContinue;

char szProgram[1024];

int icnt = 0;

if ( Process32First( hProc, &entry) )

{

do

{

strcpy(szProgram, entry.szExeFile);

cout << ++icnt << '\t'

<< szProgram<< '\t' 

<< entry.th32ProcessID << '\t' 

<< entry.pcPriClassBase << '\t' 

<< entry.dwSize << '\t'

<< entry.cntUsage << '\t'

<< entry.th32ModuleID << '\t'

<< entry.cntThreads << endl;

bContinue = Process32Next(hProc, &entry);

} while(bContinue);

}

}

CloseHandle(hProc);

}