如何将本机(NT)路径名转换为Win32路径名?
我正在报告从本机系统API收集的一些信息。 (我知道这很糟糕......但是我得到的信息是我无法得到的,而且如果/当这个时间到来时我不得不更新我的应用程序。)
本机API返回本机路径名,如
ob
所示,即SystemRootSystem32Ntoskrnl.exe
或??C:Program FilesVMWare Workstationvstor-ws60.sys
。
我可以替换公共前缀,即
std::wstring NtPathToWin32Path( std::wstring ntPath )
{
if (boost::starts_with(ntPath, L"\\?\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 4);
return ntPath;
}
if (boost::starts_with(ntPath, L"\??\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 4);
}
if (boost::starts_with(ntPath, L"\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 1);
}
if (boost::istarts_with(ntPath, L"globalroot\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 11);
}
if (boost::istarts_with(ntPath, L"systemroot"))
{
ntPath.replace(ntPath.begin(), ntPath.begin() + 10, GetWindowsPath());
}
if (boost::istarts_with(ntPath, L"windows"))
{
ntPath.replace(ntPath.begin(), ntPath.begin() + 7, GetWindowsPath());
}
return ntPath;
}
TEST(Win32Path, NtPathDoubleQuestions)
{
ASSERT_EQ(L"C:\Example", NtPathToWin32Path(L"\??\C:\Example"));
}
TEST(Win32Path, NtPathUncBegin)
{
ASSERT_EQ(L"C:\Example", NtPathToWin32Path(L"\\?\C:\Example"));
}
TEST(Win32Path, NtPathWindowsStart)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\World"), NtPathToWin32Path(L"\Windows\Hello\World"));
}
TEST(Win32Path, NtPathSystemrootStart)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\World"), NtPathToWin32Path(L"\SystemRoot\Hello\World"));
}
TEST(Win32Path, NtPathGlobalRootSystemRoot)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\World"), NtPathToWin32Path(L"\globalroot\SystemRoot\Hello\World"));
}
但如果没有一些原生或其他的API会将这些API转换为Win32路径名,我会非常惊讶。这样的API是否存在?
没有找到相关结果
已邀请:
5 个回复
肉脓措伪
辰炔诚薯
布埃郝卞簿
豪抱怒掳
弓萍功