获取启动驱动器的序列号和其他信息
我正在尝试获取启动驱动器的序列号,但我还不知道该怎么做。
我确实知道分区 =\= 硬盘驱动器,但我想要启动分区的序列号。
这是我到目前为止所拥有的:
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach (ManagementObject wmi_HD in searcher.Get())
{
// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
richTextBox1.Text += "None" + Environment.NewLine;
else
richTextBox1.Text += "Name: " + wmi_HD["Name"] + Environment.NewLine;
richTextBox1.Text += "SerialNumber: " + wmi_HD["SerialNumber"] + Environment.NewLine;
richTextBox1.Text += "MediaType: " + wmi_HD["MediaType"] + Environment.NewLine;
richTextBox1.Text += "Removable: " + wmi_HD["Removable"] + Environment.NewLine;
++i;
}
我在这里查看:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394346(v=vs.85).aspx#properties
看看我是否可以看到它是引导驱动器,我什么也没看到。
除了序列号之外,我没有得到任何回报,其他一切都是空白的。
这就是我从上面的代码中得到的结果:
姓名:
序列号:5YZ01J34
媒体类型:
可拆卸:
如何获取启动驱动器的序列号以及上面未显示的信息?
再次感谢!
I am trying to get the serial number of the boot drive and I haven't figured out how to do it.
I do understand that the partition =\= hard drive but I'd like the serial of the boot partition.
This what I have so far:
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach (ManagementObject wmi_HD in searcher.Get())
{
// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
richTextBox1.Text += "None" + Environment.NewLine;
else
richTextBox1.Text += "Name: " + wmi_HD["Name"] + Environment.NewLine;
richTextBox1.Text += "SerialNumber: " + wmi_HD["SerialNumber"] + Environment.NewLine;
richTextBox1.Text += "MediaType: " + wmi_HD["MediaType"] + Environment.NewLine;
richTextBox1.Text += "Removable: " + wmi_HD["Removable"] + Environment.NewLine;
++i;
}
I have looked here:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394346(v=vs.85).aspx#properties
To see if I could see if it was the boot drive and I don't see anything.
I'm getting nothing returned on anything but the SerialNumber, everything else is blank.
This is what I get on the above code:
Name:
SerialNumber: 5YZ01J34
MediaType:
Removable:
How do I get the serial number of the boot drive and also the information that is not showing above?
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里您谈论的是驱动器(因为它是可引导的),而不是磁盘。驱动器是逻辑,由字母(C、D...等)表示,磁盘是物理,由数字(从 0 到 N)表示)。
在您的示例中,您使用了 WMI 和
Win32_PhysicalMedia
,这是错误的,因为此类与磁盘有关,而不是驱动器。以下是您希望使用 P/Invoke 实现的功能:
现在,使用 WMI 进行同样的操作:
注意我使用了 Win32_LogicalDisk,因为我们正在谈论驱动器(此处称为逻辑磁盘)。
Here you're talking about a drive (as it's bootable), not a disk. A drive is logical and represented by a letter (C, D....etc.), and a disk is physical and represented by a number (from 0 to N).
In your example you used WMI and
Win32_PhysicalMedia
, which is wrong as this class is about disks, not drives.Here is what you want using P/Invoke:
Now, the same using WMI:
Note I've used Win32_LogicalDisk as we're talking about drives (named here logical disks).