以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 如何导入命名空间并调用GetUSBSerialNumbers() (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=186861) |
-- 作者:nsdata -- 发布时间:2023/6/4 0:29:00 -- 如何导入命名空间并调用GetUSBSerialNumbers() 百度找到一段代码,在狐表里面怎么使用GetUSBSerialNumbers?如何导入命名空间System.Management \'Imports System.Management Public Function GetUSBSerialNumbers() As List(Of String) Dim serialNumbers As New List(Of String)() Dim query As New SelectQuery("Win32_DiskDrive", "InterfaceType=\'USB\'") Dim searcher As New ManagementObjectSearcher(query) For Each drive As ManagementObject In searcher.Get() Dim pnpDeviceID As String = drive("PNPDeviceID").ToString() Dim deviceIdParts As String() = pnpDeviceID.Split("\\"c) Dim deviceId As String = deviceIdParts(deviceIdParts.Length - 1) Dim query2 As New SelectQuery("Win32_PhysicalMedia", "Tag=\'" & deviceId & "\'") Dim searcher2 As New ManagementObjectSearcher(query2) For Each drive2 As ManagementObject In searcher2.Get() Dim serialNumber As String = drive2("SerialNumber").ToString() If Not String.IsNullOrEmpty(serialNumber) Then serialNumbers.Add(serialNumber.Trim()) End If Next Next Return serialNumbers End Function |
-- 作者:有点蓝 -- 发布时间:2023/6/4 19:46:00 -- 添加外部引用:System.Management.dll:http://www.foxtable.com/webhelp/topics/1936.htm 然后把命名空间写入代码里,比如 Dim query As New System.Management.SelectQuery("Win32_DiskDrive", "InterfaceType=\'USB\'")
|
-- 作者:nsdata -- 发布时间:2023/6/6 0:04:00 -- 蓝老师是这样吗?会报错! 请仔细说说 本人还不会用 此主题相关图片如下:003.png 此主题相关图片如下:002.png |
-- 作者:有点蓝 -- 发布时间:2023/6/6 8:38:00 -- 仔细看2楼第2、3行 然后把命名空间写入代码里,比如 Dim query As New System.Management.SelectQuery("Win32_DiskDrive", "InterfaceType=\'USB\'") |