我有一个MSVC ++应用程序,吐出其他应用程序打开的文件句柄的硬盘卷path,格式如下:
DeviceHarddiskVolume4UsersUserDocumentsVisual Studio 2013ProjectsFileLockerFileLockerbinDebugTest.txt
我想将这些path转换为Windows中的这些文件的完整path。 例如,我想将上面的硬盘卷path转换为完整的Windows文件path及其相应的驱动器号:
C:UsersUserDocumentsVisual Studio 2013ProjectsFileLockerFileLockerbinDebugTest.txt
我看了网上,但我还没有find任何明确的资源做这个以编程方式。 如何做呢?
与多个用户的WCF REST服务基本authentication
以编程方式更改Internet Explorer设置?
Process.Start – 如何将启动的可执行文件发送到后台(C#)
ngen如何工作?
如何在.NET中确定cpucaching大小?
在我的新窗口安装Image.FromStream不以相同的方式工作
如何以编程方式禁用系统设备?
.NET和本机C ++应用程序之间进行通信的最佳方式
定义执行程序的工作目录(C#)
在这个exception消息中引用了什么“配额”:没有足够的配额可用于处理此命令
卷管理功能
这里是一个来自MSDN的例子:
显示音量路径
#include <windows.h> #include <stdio.h> void displayVolumePaths( __in PWCHAR VolumeName ) { DWORD CharCount = MAX_PATH + 1; PWCHAR Names = NULL; PWCHAR NameIdx = NULL; BOOL Success = FALSE; for (;;) { // // Allocate a buffer to hold the paths. Names = (PWCHAR) new BYTE [CharCount * sizeof(WCHAR)]; if ( !Names ) { // // If memory can't be allocated,return. return; } // // Obtain all of the paths // for this volume. Success = GetVolumePathNamesForVolumeNameW( VolumeName,Names,CharCount,&CharCount ); if ( Success ) { break; } if ( GetLastError() != ERROR_MORE_DATA ) { break; } // // Try again with the // new suggested size. delete [] Names; Names = NULL; } if ( Success ) { // // display the varIoUs paths. for ( NameIdx = Names; NameIdx[0] != L' '; NameIdx += wcslen(NameIdx) + 1 ) { wprintf(L" %s",NameIdx); } wprintf(L"n"); } if ( Names != NULL ) { delete [] Names; Names = NULL; } return; } void __cdecl wmain(void) { DWORD CharCount = 0; WCHAR DeviceName[MAX_PATH] = L""; DWORD Error = ERROR_SUCCESS; HANDLE FindHandle = INVALID_HANDLE_VALUE; BOOL Found = FALSE; size_t Index = 0; BOOL Success = FALSE; WCHAR VolumeName[MAX_PATH] = L""; // // Enumerate all volumes in the system. FindHandle = FindFirstVolumeW(VolumeName,ARRAYSIZE(VolumeName)); if (FindHandle == INVALID_HANDLE_VALUE) { Error = GetLastError(); wprintf(L"FindFirstVolumeW Failed with error code %dn",Error); return; } for (;;) { // // Skip the \? prefix and remove the trailing backslash. Index = wcslen(VolumeName) - 1; if (VolumeName[0] != L'\' || VolumeName[1] != L'\' || VolumeName[2] != L'?' || VolumeName[3] != L'\' || VolumeName[Index] != L'\') { Error = ERROR_BAD_PATHNAME; wprintf(L"FindFirstVolumeW/FindNextVolumeW returned a bad path: %sn",VolumeName); break; } // // QueryDosDeviceW does not allow a trailing backslash,// so temporarily remove it. VolumeName[Index] = L' '; CharCount = QueryDosDeviceW(&VolumeName[4],DeviceName,ARRAYSIZE(DeviceName)); VolumeName[Index] = L'\'; if ( CharCount == 0 ) { Error = GetLastError(); wprintf(L"QueryDosDeviceW Failed with error code %dn",Error); break; } wprintf(L"nFound a device:n %s",DeviceName); wprintf(L"nVolume name: %s",VolumeName); wprintf(L"nPaths:"); displayVolumePaths(VolumeName); // // Move on to the next volume. Success = FindNextVolumeW(FindHandle,VolumeName,ARRAYSIZE(VolumeName)); if ( !Success ) { Error = GetLastError(); if (Error != ERROR_NO_MORE_FILES) { wprintf(L"FindNextVolumeW Failed with error code %dn",Error); break; } // // Finished iterating // through all the volumes. Error = ERROR_SUCCESS; break; } } FindVolumeClose(FindHandle); FindHandle = INVALID_HANDLE_VALUE; return; }
澄清:
卷名称(或GUID)类似于\?Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
盘符是类似于C:
FindFirst/NextVolume为您提供卷名称列表。
QueryDosDevice为您提供一个来自卷名的设备名称。
GetVolumePathNamesForVolumeName为您提供来自卷名的驱动器盘符。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。