简体   繁体   English

在Windows XP上无法获取物理磁盘序列号

[英]Getting Physical Disks serial number doesn't work on windows XP

i'm trying to get physical disks serial number using C# adn WMI 我正在尝试使用C#和WMI获取物理磁盘序列号

var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
foreach (ManagementObject mo in searcher.Get())
{
    Console.WriteLine("Serial: {0}", mo["SerialNumber"]);
}

this code show all serial numbers of HDD and flash removable stick, but it fails to get flash removable disk on windows XP and gives me null for the removable disks but get the HDD serial number correctly. 这段代码显示了HDD和闪存可移动棒的所有序列号,但是它无法在Windows XP上获取闪存可移动磁盘,并为我提供了可移动磁盘的空值,但正确获得了HDD序列号。 any ideas what's wrong ? 任何想法有什么问题吗?

my thinking is that windows XP needs update, anyone knows what is the update needed ? 我的想法是Windows XP需要更新,任何人都知道需要什么更新? i need the specific update to include it with my software. 我需要特定的更新才能将其包含在我的软件中。

any other reasons why this happens ? 还有其他原因导致这种情况发生吗?

As far as I'm aware, it's not guaranteed that a storage device will report a serial number even if the code is otherwise correctly done. 据我所知,即使代码正确完成,也不能保证存储设备将报告序列号。 In the past I worked on some licensing code and ran into similar problems in various environments when using WMI. 过去,我研究了一些许可代码,并且在使用WMI时在各种环境中遇到了类似的问题。 In my experience, it's a lot more reliable to use low-level API calls (but it's a lot more coding / testing) but even then, you're not guaranteed to get a serial number back. 以我的经验,使用低级API调用要可靠得多(但是要进行更多的编码/测试),但是即使那样,也不能保证您会获得序列号。

Some environments where you may run into problems (not a complete list): 您可能会遇到问题的某些环境(不是完整列表):

  • Windows XP Windows XP
  • Virtual machines 虚拟机
  • SATA drives SATA驱动器
  • Various other devices that present themselves as HDDs but really aren't 各种其他设备将自己显示为HDD,但实际上不是
  • etc. 等等

You can look at this article on Code Project and see if it works better for you. 您可以在Code Project上查看此文章 ,看看它是否对您更好。

If you're trying to do this for some kind of licensing solution, you may want to consider getting more hardware information so that if one piece of information is missing you still have something else to go with. 如果您尝试通过某种许可解决方案来执行此操作,则可能需要考虑获取更多的硬件信息,这样,如果缺少一条信息,您仍然可以进行其他操作。 It's also worth reading about spoofing HDD serial numbers . 欺骗HDD序列号也值得一读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM