以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [讨论]获取电脑当前所有移动磁盘(即USB)序列号 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=188358) |
-- 作者:nsdata -- 发布时间:2023/9/15 17:48:00 -- [讨论]获取电脑当前所有移动磁盘(即USB)序列号 蓝老您好,请问如何获取电脑当前所有U盘(当前电脑可能插了N个U盘都要获取)的序列号?有没代码或dll推荐下
|
-- 作者:有点蓝 -- 发布时间:2023/9/16 11:32:00 -- 引用添加System.Management.dll,http://www.foxtable.com/webhelp/topics/1936.htm Dim diskArray As String() Dim driveNumber As String Dim searcher As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition") For Each dm As System.Management.ManagementObject In searcher.Get() Dim inValue As String = dm("Antecedent").ToString() Dim posFoundStart = inValue.IndexOf("""") Dim posFoundEnd = inValue.IndexOf("""", posFoundStart + 1) Dim parsedValue = inValue.Substring(posFoundStart + 1, (posFoundEnd - posFoundStart) - 1) diskArray = parsedValue.Split(","c) driveNumber = diskArray(0).Remove(0, 6).Trim() Dim disks = New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") For Each disk As System.Management.ManagementObject In disks.[Get]() If disk("Name").ToString() = ("\\\\.\\PHYSICALDRIVE" & driveNumber) And disk("InterfaceType").ToString() = "USB" Then Dim deviceId As String = disk("PNPDeviceID").ToString() Dim splitDeviceId = deviceId.Split("\\"c) Dim arrayLen = splitDeviceId.Length - 1 Dim serialArray = splitDeviceId(arrayLen).Split("&"c) Dim serial = serialArray(0) Output.Show(serial) End If Next Next |
-- 作者:nsdata -- 发布时间:2023/9/17 0:56:00 -- 可以哦 蓝老厉害,小弟臣服。。。上面能获取一个usb的id,如果电脑插了N个USB 如何同时列出N个usb ID?
|
-- 作者:有点蓝 -- 发布时间:2023/9/17 20:19:00 -- 上面代码就是列出所有的 |