首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

U 盘的ID号的获取!该如何处理

2012-02-12 
U 盘的ID号的获取!如有人知道请赐教!急![解决办法]VB codeOption ExplicitPrivate Sub Command1_Click()

U 盘的ID号的获取!
如有人知道请赐教!急!

[解决办法]

VB code
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
[解决办法]
VB code
        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 

热点排行