Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks,
I'm trying to get the list of all processes which are running on a user session.
While testing the same in Windows 2008 SP2, with a non-admin user, I could find that the below piece of code fetches all the process which belongs to the admin user.

Is there a way to get the list of process which are running only on that user (non-admin)?

Please find the code snippet below:

C++
DWORD procID = 0;
FILE *fp;

PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);


HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if ( processesSnapshot == INVALID_HANDLE_VALUE )
{
    return;
}
	
fp = _tfopen(_T("C:\\Process_List.txt") , _T("a+") );

if (fp == NULL) {
   MessageBox(_T("Can't open File"));
   return;
}
   
Process32First(processesSnapshot, &processInfo);
	
	
_ftprintf(fp, _T("\n Process: %s :: Process ID: %d"), processInfo.szExeFile, processInfo.th32ProcessID);
procID =  processInfo.th32ProcessID;

if (procID == 0)
{
	while ( Process32Next(processesSnapshot, &processInfo) )
	{
		_ftprintf(fp, _T("\n Process: %s :: Process ID: %d"), processInfo.szExeFile, processInfo.th32ProcessID);
	}
}

fclose(fp);
CloseHandle(processesSnapshot);

Thanks In Advance.

regards,
Rajesh
Posted
Updated 20-Jun-13 7:29am
v2

1 solution

You'll likely have to walk through them all and filter for the ones you want to work with.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900