我需要将path(例如C:
)转换为该卷的GUID形式(例如\?Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
)
c#中有这样的函数吗?
您需要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);