Winapi 为什么GetVolumeInformation为序列号返回整数?

Winapi 为什么GetVolumeInformation为序列号返回整数?,winapi,Winapi,如何确定计算机中的物理驱动器和分区?我曾尝试使用GetVolumeInformation中的卷序列号,但震惊地发现它返回的是一个数字而不是字母数字值 [DllImport("Kernel32.dll", SetLastError = true)] extern static bool GetVolumeInformation(string vol, StringBuilder name, int nameSize, out uint serialNum, out uint maxNameLen,

如何确定计算机中的物理驱动器和分区?我曾尝试使用GetVolumeInformation中的卷序列号,但震惊地发现它返回的是一个数字而不是字母数字值

[DllImport("Kernel32.dll", SetLastError = true)]
extern static bool GetVolumeInformation(string vol, StringBuilder name, int nameSize, out uint serialNum, out uint maxNameLen, out uint flags, StringBuilder fileSysName, int fileSysNameSize);

我需要知道USB拇指驱动器、CD或DVD或硬盘驱动器在连接到不同的计算机时是同一个物理设备。我还需要知道,即使在用户重命名分区或卷或更改驱动器号后,分区或卷仍然是相同的。

它还应该返回什么?它只是文件系统在格式化时分配的一个32位数字

如果您想将其格式化为
dir
返回的内容,只需使用

serialNumber.ToString("X8");

你混淆了两件不同的事情。文件说:

lpVolumeSerialNumber[输出,可选]

此函数用于返回硬盘格式化时操作系统分配的卷序列号

这是操作系统分配的序列号。它分配了它,我相信它知道返回它的正确格式

它接着说:

要以编程方式获取制造商分配的硬盘序列号,请使用Windows Management Instrumentation(WMI)Win32_PhysicalMedia属性SerialNumber