CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: ProcessList

  1. #1
    Join Date
    Aug 2008
    Location
    C:\Windows\System32
    Posts
    47

    ProcessList

    Hey guys can someone show me how to get currently running processes and add them to a listbox with handle hStaticx. I'll be very grateful if someone could help.

    ~Cha0sBG

  2. #2
    Join Date
    Dec 2007
    Posts
    33

    Re: ProcessList

    Code:
    #include <windows.h>
    #include <tlhelp32.H>
    #include <iostream>
    
    using namespace::std;
    
    int main()
    {
    	HANDLE			process;
    	PROCESSENTRY32		ProcessList;
    
    
    	process = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    
    	if (process == INVALID_HANDLE_VALUE)
    	{
            return 0;
    	}
    
    	if(Process32First(process,&ProcessList)==FALSE)
    	{
    		return 0;
    	}
    
    	do
    	{
    
    		cout << ProcessList.szExeFile << " " << ProcessList.th32ProcessID << endl;
    
    	}while(Process32Next(process, &ProcessList) != FALSE);
    
    	return 0;
    }
    here is a simple code that print out to a standart console window the current running proccess(that aren't hidden or anything....).
    the PROCESSENTRY32 structure contains many more information that you might find useful.

    hope it helped.

  3. #3
    Join Date
    May 2007
    Posts
    437

  4. #4
    Join Date
    Aug 2008
    Location
    C:\Windows\System32
    Posts
    47

    Re: ProcessList

    EDIT: Sorry just had the wrong control :S
    Last edited by Cha0sBG; June 29th, 2009 at 01:25 PM.

  5. #5
    Join Date
    Dec 2007
    Posts
    33

    Re: ProcessList

    There is no error checking in your code.
    Make sure your code gets the process names properly.
    Call MessageBox in the do..while loop.

  6. #6
    Join Date
    Aug 2008
    Location
    C:\Windows\System32
    Posts
    47

    Re: ProcessList

    No i just had the handle to a Static mixed it with my ListBox your code is perfect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured