将路径转换为其GUID形式

时间:2014-08-26 14:13:21

标签: c# guid filepath

我需要将路径(例如C:\)转换为该卷的GUID表单(例如\\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\)。

C#中是否有任何类似的功能?

1 个答案:

答案 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);