Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:[讨论]获取电脑当前所有移动磁盘(即USB)序列号

1楼
nsdata 发表于:2023/9/15 17:48:00

  蓝老您好,请问如何获取电脑当前所有U盘(当前电脑可能插了N个U盘都要获取)的序列号?有没代码或dll推荐下
2楼
有点蓝 发表于: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

3楼
nsdata 发表于:2023/9/17 0:56:00
 
   可以哦 蓝老厉害,小弟臣服。。。上面能获取一个usb的id,如果电脑插了N个USB 如何同时列出N个usb ID?
4楼
有点蓝 发表于:2023/9/17 20:19:00
上面代码就是列出所有的
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02344 s, 2 queries.