雅林源居 发表于 2014-6-28 09:07
VBA中U盘绑定命令
Sub auto_open()
Dim objWMIService As Object
这个不错,稍微修改一下,获取U盘的物理序列号:
Sub GetUdiskNo() DimobjWMIService As Object, colItems As Object, objitem As Object, a, b, c, d, e,U_Dist, aaa SetobjWMIService = GetObject("winmgmts:\\.\root\cimv2") SetcolItems = objWMIService.ExecQuery("Select * From Win32_USBHub") For Eachobjitem In colItems a =objitem.DeviceID If aLike "*VID*" Then b= Split(a, "\") c= Split(b(UBound(b) - 1), "&") d= Split(c(UBound(c) - 1), "_") e= Split(c(UBound(c)), "_") U_Dist = d(UBound(d)) + e(UBound(e)) + b(UBound(b)) ' If U_Dist ="13FE3823070B243F2821EE34" Then Exit Sub 'U盘物理序号 EndIf Next 'CreateObject("WScript.Shell").Popup "U盘系列号不对,自动关闭EXCEL!",1, "雅林-警告" 'ThisWorkbook.Close False MsgBox"U盘物理序号: " & vbCr & _ U_Dist, 64 + 0, "提醒" End Sub
|