$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colEvents = $objWMIService.ExecNotificationQuery _
("Select * From __InstanceOperationEvent Within 5 Where " _
& "TargetInstance isa 'Win32_LogicalDisk'")
While 1
$objEvent = $colEvents.NextEvent
If $objEvent.TargetInstance.DriveType = 2 Then
Select
Case $objEvent.Path_.Class()="__InstanceCreationEvent"
MsgBox(262144, "哎呀", "可移动磁盘" & $objEvent.TargetInstance.DeviceId & "已经插进来了!",3)
;Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
;Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
MsgBox(262144, "哎呀", "可移动磁盘" & $objEvent.TargetInstance.DeviceId & "被拔出去了~",3)
EndSelect
EndIf
WEnd
|