Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding processes.

Status
Not open for further replies.

sysa1

Programmer
Jun 4, 2002
3
0
0
MY
HI,

i am a newbie to C++/C.
In my project i need to know that what process are currently running on the PC.. I am talking about the processes that we can see under the process tab of Task Manager.
i even dont know that from where should i start for this.
Please help with some codes or some links to start with..

thanx.
 
Hi,
First if the process has a window you can use the API "FindWindow"
but more effective way i think is to use the API EnumProcesses()
search a little for it if you cant do, i will help you
[pc3]
 
Thanx decoder, ok first i will look for EnumProces and try to do it myself if not i will come back to you tomorrow.
thanx again
see u tomorrow ,
bye,
 
hi again,
i will be abroad for the next week which means there is no way for me to connect to internet. ( i prefer taking photos and visit places i havent met :) ) so here is a sample dummy code to show a path.
------------------
DWORD dwIdProcesses[200];
DWORD dwcb = 200;
DWORD dwPIDLength;
HANDLE hProcess = NULL;
char pProcessName[50];
int i = 0;
BOOL bFlag = TRUE;
int n;
DWORD dwReturn;


BOOL bReturn = EnumProcesses(dwIdProcesses,dwcb,&dwPIDLength);
bReturn =GetLastError();
n = dwPIDLength / sizeof(DWORD);
while ( (bFlag) AND (i < n))
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwIdProcesses);
GetModuleBaseName(hProcess,NULL,LPTSTR(pProcessName),50);
dwReturn = GetLastError();
CloseHandle(hProcess);
// here you got the name of the process.
------------------
headers to include besides standart ones are :
#include<psapi.h>
#include<process.h>
and lib to add to project is : psapi.lib
------------------
[pc3]

Read between the lines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top