본문 바로가기

Test Code/C++

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

사용중인 프로세스 조회


- 파일명 : 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);

}



'Test Code > C++' 카테고리의 다른 글

c++ time.h  (0) 2013.12.24
c++ 문자를 숫자로 숫자를 문자로  (0) 2013.12.24
Mingw - Split 함수 만들기  (0) 2013.12.21
WinAPI - GetTickCount 함수로 sleep 함수 만들기  (0) 2013.12.21
WinAPI - 윈도우폼에 아이콘 넣기  (0) 2013.12.20