【问题标题】:How to get serial number of USB-Stick in C#如何在 C# 中获取 USB-Stick 的序列号
【发布时间】:2010-10-01 18:57:34
【问题描述】:

如何在 C# 中获取 USB-Stick 或 USB-HardDrive 的内部序列号?

【问题讨论】:

    标签: c# usb usb-drive


    【解决方案1】:

    试试这个:

    // add a reference to the System.Management assembly and
    // import the System.Management namespace at the top in your "using" statement.
    // Then in a method, or on a button click:
    
    ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
    foreach (ManagementObject currentObject in theSearcher.Get())
    {
       ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
       MessageBox.Show(theSerialNumberObjectQuery["SerialNumber"].ToString());
    }
    

    来源:http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/f4447ed3-7e5f-4635-a28a-afff0b620156/

    【讨论】:

    • 干得好,我得到了序列号我如何获得 USB 的实例 ID。
    【解决方案2】:

    使用Win32的解决方案is described here

    编辑:原始链接似乎已丢失。以上为缓存副本,作者还在VB.Net中写了一些示例代码still online here

    【讨论】:

    • 谢谢,我一直在寻找这样的东西!
    【解决方案3】:

    我对 Yuval Adam 提供的解决方案有疑问,因为我尝试的每个 USB 记忆棒在 Windows 7 上都返回空白。

    我通过查看当前对象的属性 PNPDeviceId 解决了这个问题。

    例如

    currentObject["PNPDeviceID"].ToString();
    

    不确定这是否有效,但它在我尝试过的 3 个 USB 记忆棒上对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多