Gets the full path (code) of the executable (EXE) file corresponding to the specified process

Source: Internet
Author: User

1 " Psapi.h " 2 #pragma   Comment (lib,   "Psapi.lib")
Need to include header file Oh!

1 /*function: Gets the full path of the executable (EXE) file corresponding to the specified process2 * Parameter: hprocess-process handle. Must have process_query_information or3 process_query_limited_information Permissions4 * Sfilepath-the path of the executable file corresponding to the process handle hprocess5 * return value:6  */7 voidGetprocessfilepath (in HANDLE hprocess, out cstring&Sfilepath)8 {9Sfilepath = _t ("");TenTCHAR Tsfiledospath[max_path +1]; OneZeroMemory (Tsfiledospath,sizeof(TCHAR) * (MAX_PATH +1)); A     if(0= = Getprocessimagefilename (hprocess, Tsfiledospath, MAX_PATH +1)) -     { -         return; the     } -  -     //get logic Drive string length -UINT Uilen = GetLogicalDriveStrings (0, NULL); +     if(0==Uilen) -     { +         return; A     } at  -Ptstr plogicdrivestring =NewTchar[uilen +1]; -ZeroMemory (plogicdrivestring, Uilen +1); -Uilen =getlogicaldrivestrings (Uilen, plogicdrivestring); -     if(0==Uilen) -     { in         Delete[]plogicdrivestring; -         return; to     } +  -TCHAR szdrive[3] = TEXT (" :"); thePtstr Pdosdrivename =NewTchar[max_path]; *Ptstr Plogicindex =plogicdrivestring; $ Panax Notoginseng      Do -     { theszdrive[0] = *Plogicindex; +Uilen =Querydosdevice (szdrive, Pdosdrivename, MAX_PATH); A         if(0==Uilen) the         { +             if(Error_insufficient_buffer! =GetLastError ()) -             { $                  Break; $             } -  -             Delete[]pdosdrivename; thePdosdrivename =NewTchar[uilen +1]; -Uilen = Querydosdevice (szdrive, pdosdrivename, Uilen +1);Wuyi             if(0==Uilen) the             { -                  Break; Wu             } -         } About  $Uilen =_tcslen (pdosdrivename); -         if(0==_tcsnicmp (Tsfiledospath, Pdosdrivename, Uilen)) -         { -Sfilepath.format (_t ("%s%s"), szdrive, Tsfiledospath +Uilen); A              Break; +         } the  -          while(*plogicindex++); $} while(*plogicindex); the  the     Delete[]plogicdrivestring; the     Delete[]pdosdrivename; the}

Gets the full path (code) of the executable (EXE) file corresponding to the specified process

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.