GetProcessImageFileName获取进程路径

本文深入探讨了C++中用于将Dos设备路径转换为逻辑路径的DosDevicePath2LogicalPath函数的实现原理及使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pe.th32ProcessID);
if ( GetProcessImageFileName(hProcess,szFilePath,MAX_PATH)!=0 ){
mystring strFilePath = CCommon::DosDevicePath2LogicalPath(szFilePath);

}

 DosDevicePath2LogicalPath代码摘自:ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/fileio/fs/obtaining_a_file_name_from_a_file_handle.htm

mystring CCommon::DosDevicePath2LogicalPath(LPCTSTR lpszDosPath)
{
mystring strResult;

// Translate path with device name to drive letters.
TCHAR szTemp[MAX_PATH];
szTemp[0] = '\0';

if ( lpszDosPath==NULL || !GetLogicalDriveStrings(_countof(szTemp)-1, szTemp) ){
return strResult;
}


TCHAR szName[MAX_PATH];
TCHAR szDrive[3] = TEXT(" :");
BOOL bFound = FALSE;
TCHAR* p = szTemp;

do{
// Copy the drive letter to the template string
*szDrive = *p;

// Look up each device name
if ( QueryDosDevice(szDrive, szName, _countof(szName)) ){
UINT uNameLen = (UINT)_tcslen(szName);

if (uNameLen < MAX_PATH)
{
bFound = _tcsnicmp(lpszDosPath, szName, uNameLen) == 0;

if ( bFound ){
// Reconstruct pszFilename using szTemp
// Replace device path with DOS path
TCHAR szTempFile[MAX_PATH];
_stprintf_s(szTempFile, TEXT("%s%s"), szDrive, lpszDosPath+uNameLen);
strResult = szTempFile;
}
}
}

// Go to the next NULL character.
while (*p++);
} while (!bFound && *p); // end of string

return strResult;
}

转载于:https://www.cnblogs.com/daxingxing/archive/2011/10/08/2202283.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值