Converting a path to its GUID form

I need to convert the path (for example C:\

) to this form of volume GUID (for example \\\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\

).

Is there any function in C # that does something like this?

+3


source to share


1 answer


You need 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);

      

+7


source







All Articles