U 盘的ID号的获取!
如有人知道请赐教!急!
[解决办法]
Option ExplicitPrivate Sub Command1_Click()'声明成注释里面的类型应先勾选“工程”-》“引用”里面的“Microsoft WMI Scripting VX.X Library”On Error Resume NextDim sObjTxt As String, oWMINameSpace As Object 'SWbemServices'Dim ObjSet As SWbemObjectSet, Obj As SWbemObjectExDim ObjSet As Object, Obj As ObjectSet oWMINameSpace = GetObject("winmgmts:"): Text1.Text = ""Set ObjSet = oWMINameSpace.InstancesOf("Win32_USBControllerDevice")For Each Obj In ObjSet sObjTxt = Obj.Dependent 'Obj.GetObjectText_ If InStrRev(sObjTxt, "USBSTOR") Then Text1.Text = Text1.Text & sObjTxt & vbNewLine End IfNextIf Len(Text1.Text) = 0 Then MsgBox "你没有插入U盘吧?", vbExclamation, "错误"End Sub
[解决办法]
Dim fso As New FileSystemObject Dim dSerialNumber As Long Select Case fso.GetDrive(fso.GetDriveName("D:")).DriveType Case 2 If UCase(GetDriveBusType(fso.GetDriveName("D:"))) = "USB" Then dSerialNumber = fso.GetDrive(fso.GetDriveName("D:")).SerialNumber End If End Select