方法1 VBS+Wmi- set objShell = CreateObject ("Wscript.Shell")
- Set oLocator = CreateObject ("WbemScripting.SWbemLocator")
- Set oSink = WScript.CreateObject ("WbemScripting.SWbemSink","Event_")
- Set oWMISvc = oLocator.ConnectServer
- oWMISvc.ExecNotificationQueryAsync oSink, "Select * From __InstanceCreationEvent WITHIN 5 " & _
- "Where TargetInstance ISA 'Win32_LogicalDisk'"
- Do
- WScript.Sleep 2000
- Loop
-
- Sub Event_OnObjectReady(oEventSource,oContext)
- WScript.Echo "USB 设备已插入,盘符为 "&oEventSource.TargetInstance.Name
- End Sub
复制代码 方法2 VBS+FileSystemObject-
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set DC = Fso.Drives
- Do
- For Each D in DC
- aDisk=""
- If D.DriveType = 1 Then
- aDisk = aDisk & D.DriveLetter & ": "
- End If
- Next
- aDisk = Replace(aDisk, "A: ","")
- If aDisk = "" Then
- Wscript.sleep 8000
- Else
- WScript.Echo "USB 设备已插入,盘符为 "&aDisk
- End If
- Wscript.sleep 20000
- Loop
复制代码
|