+ Reply to Thread
Results 1 to 2 of 2

Thread: get parent process id from child process id

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    27

    get parent process id from child process id

    I required to get parent process Id from the child process id. I do not find any direct API for this. How can I do this using WIN32 APIs?
    I need to get the parent process ID if I provide child process ID.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    29
    Use following example to get parent process ID from child process ID.

    Code:
    DWORD GetParentProcessID(DWORD dwProcessID)
    {
    	DWORD dwParentProcessID = -1 ;
    	HANDLE			hProcessSnapshot ;
    	PROCESSENTRY32	processEntry32 ;
    	
    	hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) ;
    	if(hProcessSnapshot != INVALID_HANDLE_VALUE)
    	{
    		processEntry32.dwSize = sizeof(PROCESSENTRY32) ;
    		if(Process32First(hProcessSnapshot, &processEntry32))
    		{
    			do
    			{
    				if (dwProcessID == processEntry32.th32ProcessID)
    				{
    					dwParentProcessID = processEntry32.th32ParentProcessID ;
    					break ;
    				}
    			}
    			while(Process32Next(hProcessSnapshot, &processEntry32)) ;
    			
    			CloseHandle(hProcessSnapshot) ;
    		}
    	}
    
    	return dwParentProcessID ;
    }
    Hope this helps you.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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