gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:52:32 28 4
gpt4 key购买 nike

如何在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com