View Full Version : RE: Find out running processes from command prompt

09-26-2001, 01:49 AM
Hi All,
I am looking for a any command in MS-DOS or any function in C language, with help of that I can find running processes in my compter. That means, We can find running processes in task manager, but I would like to find out that same thing from command prompt or from C program. So please let me know.. if any one has any idea... waiting for reply.....

10-17-2001, 12:20 AM
You can't do that in MSDOS mode.

10-18-2001, 07:15 AM
If it is a console window from Windows use:

DWORD h1 = GetCurrentProcessId();
HANDLE h2 = OpenProcess(PROCESS_ALL_ACCESS, 0, h1);

the code abowe is to retrive your process handle

Use the following code to retrive all the ID from the system
but it works only with Win2k and you will need PSAPI.DLL

HMODULE hPsapi = LoadLibrary("PSAPI.DLL");
if (hPsapi == NULL) return 1;
typedef BOOL (__stdcall * EnumProc)(DWORD*,DWORD,DWORD*);
EnumProc enumProcessesStub = NULL;
enumProcessesStub = (EnumProc)GetProcAddress(hPsapi,"EnumProcesses");
if (!enumProcessesStub) return 1;

DWORD needed = 0;
DWORD* dwArray = new DWORD[2000];
enumProcessesStub(dwArray ,0,&needed);
if (enumProcessesStub(dwArray,2000*sizeof(DWORD),&needed))
printf("%d ids retrived\n", needed);
// free memory
delete dwArray;
// free psapi.dll