我需要将路径(例如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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
713 次 |
| 最近记录: |