1 DWORD showparentprocessinfo ()2 {3typedef LONG (WINAPI *Procntqsip) (Handle,uint,pvoid,ulong,pulong); 4 Procntqsip ntqueryinformationprocess; 5Ntqueryinformationprocess =(PROCNTQSIP) GetProcAddress (6GetModuleHandle (_t ("Ntdll")), 7 "ntqueryinformationprocess" 8 ); 9 Ten if(!ntqueryinformationprocess) One return 0; A -DWORD dwId =:: GetCurrentProcessId (); - LONG status; theDWORD Dwparentpid =0; - HANDLE hprocess; - w_process_basic_information PBI; - + //Get Process Handle -hprocess =openprocess (process_query_information, NULL, dwId); + if(!hprocess) A return 0; at - //Retrieve Information -Status =ntqueryinformationprocess (hprocess, - Processbasicinformation, -(PVOID) &PBI, - sizeof(w_process_basic_information), in NULL - ); to + //Copy Parent Id on Success - if(!status) the { *Dwparentpid =PBI. Inheritedfromuniqueprocessid; $HANDLE hparentprocess =NULL;Panax Notoginsenghparentprocess = OpenProcess (process_query_information|Process_vm_read, NULL, dwparentpid); - if(hparentprocess) the { +TCHAR Sztemp[max_path] = {0}; ATCHAR Szprocessname[max_path] = {0}; theDWORD Dwerr =:: Getmodulefilenameex (Hparentprocess,null,sztemp,max_path); + :: Getlongpathname (Sztemp, szProcessName, MAX_PATH); - if(Dwerr) $Log4cxx (Log4cxx__info, ModuleName, _t ("caller=%s, parentprocessid=%d"), szProcessName, dwparentpid); $ Else -Log4cxx (Log4cxx__info, ModuleName, _t ("caller=%s, parentprocessid=%d, lasterror=%d"), szProcessName, Dwparentpid, dwerr); - } the CloseHandle (hparentprocess); - }Wuyi the CloseHandle (hprocess); - Wu returnDwparentpid; -}
Results
Caller=c:\program Files (x86) \wind\wind.net.client\windnet\bin\wmain.exe, parentprocessid=6012
Get caller Process Information