c# - 如何在C#中获取USB-Stick的序列号

标签 c# usb usb-drive

如何在 C# 中获取 U 盘或 USB 硬盘的内部序列号?

最佳答案

试试这个:

// 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/

关于c# - 如何在C#中获取USB-Stick的序列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/450009/

相关文章:

Linux:在连接的 USB 串行加密狗上启动守护进程

android - Android 10 中没有设备过滤器的 USB_DEVICE_ATTACHED

c++ - 如何使用环境变量添加现有项目?

c# - 无法从文件夹中获取文件

c# - 用户登录逻辑属于哪里?三层应用

c# - 我的 IEnumerable 是否应该枚举作为参数传递给 AddRange() 之类的方法的 IEnumerable?

c# - 使用其关系中的属性为子类建模的正确方法

python - 为 Linux 创建 USB 设备驱动程序

batch-file - Windows : script/program for USB key that opens a console, 并设置路径和工作目录

windows - 使用 VBScript 查找 USB 盘符