我需要将路径(例如C:\
)转换为该卷的GUID表单(例如\\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\
)。
C#中是否有任何类似的功能?
答案 0 :(得分:7)
您需要P / Invoke GetVolumeNameForVolumeMountPoint
:
static string GetVolumeGuidPath(string mountPoint)
{
StringBuilder sb = new StringBuilder(50);
GetVolumeNameForVolumeMountPoint(mountPoint, sb, 50);
return sb.ToString();
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetVolumeNameForVolumeMountPoint(
string lpszVolumeMountPoint,
[Out] StringBuilder lpszVolumeName,
int cchBufferLength);