process IDīs

This is a discussion on process IDīs within the C++ Programming forums, part of the General Programming Boards category; how are u doing? i havent posted for about 4 months i think.. anyway im looking for a way to ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    process IDīs

    how are u doing? i havent posted for about 4 months i think..

    anyway im looking for a way to get a windows processes ID &/or HANDLE.
    i have googled for about 2 hours all i find is some bad codes with lots of errors etc. ive also looked thru MSDN.
    anyone got the experience.

    ps where can i find ms. platform SDK?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Platform SDK (search on google "microsoft platform sdk", first result):
    http://www.microsoft.com/msdownload/...sdk/sdkupdate/

    Can't tell you anything about getting process ID's though. This probably belongs on the Windows forum.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i visited that site but i thought it was just for updating..
    your right this should be in the windows forum.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i see but how does that work?

    DWORD GetCurrentProcessId(void);

    HANDLE GetCurrentProcess(void);

    i must have something to past, dont know where to get them from?!

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Could you tell us exactly what you are trying to achieve? For which process do you need a process ID? What are you going to use it for? With a little more information we can probably provide more detailed help.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i want a way to get any process ID
    MSN for example

  8. #8
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Easy... Here's how to get all running processes info. You'll need:

    Code:
    #include <iostream>
    #include <windows.h>
    #include <tlhelp32.h>
    
    BOOL ListProcesses(){	
    	HANDLE hSnapshot;
    	PROCESSENTRY32 process;
    
    	hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD, 0);//2nd parameter ignored
    	if(hSnapshot==INVALID_HANDLE_VALUE) return FALSE;
    
    	ZeroMemory(&process, sizeof(PROCESSENTRY32));
    	process.dwSize=sizeof(PROCESSENTRY32);
    
    	if(!Process32First(hSnapshot, &process))
    		return FALSE;
    
    	do{
    		std::cout<<process.szExeFile<<"\tPID: "<<process.th32ProcessID<<std::endl;
    	}while(Process32Next(hSnapshot, &process));
    	
    	CloseHandle(hSnapshot);
    
    	return TRUE;
    }
    
    int main(){
    	std::cout<<"Listing processes\n";
    	ListProcesses();
    	std::cin.get();
    	return 0;
    }
    Now adapt this code to your needs.
    NOTE the 32 in the types names. That referes to 32-bit processes. Later with 64-bit CPU we'll use 64, for 64 bit processes, and 32 for 32 bit processes running on 64 bit machine, although emulated.
    Last edited by xErath; 12-05-2004 at 01:47 PM.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    thx m8 thats probably what i was looking for!

  10. #10
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    http://msdn.microsoft.com/library/de..._processes.asp

    That link shows code for listing all the processes (That code gives process name, like explorer.exe and also gives process ID of each one). My suggestion is make a simple class to hold process name, PID, and handle. Then make a list of that class, and instead of printing them to the screen, insert them into a list, then you have a list you can search through processes and such. I have just recently done this, if you want any help, IM or email me.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 01:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21