Get caller Process Information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.