Thread: RE: Find out running processes from command prompt

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    RE: Find out running processes from command prompt

    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.....
    Thanks,
    Samir

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    You can't do that in MSDOS mode.
    // Gliptic

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Hi
    If it is a console window from Windows use:
    Code:
      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
    Code:
    	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
    	FreeLibrary(hPsapi);
    Last edited by damyan; 10-18-2001 at 07:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 11:08 AM
  2. Task Manager: Applications vs Processes
    By Shwick in forum Windows Programming
    Replies: 3
    Last Post: 08-14-2008, 06:47 AM
  3. Processes not dying
    By Elkvis in forum Linux Programming
    Replies: 12
    Last Post: 04-23-2008, 08:59 AM
  4. Won't Return pointer, i can't find why...
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 08:50 PM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM