strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Query = "Select * From __InstanceOperationEvent Within 1 " & _
" Where TargetInstance isa ""Win32_LogicalDisk"""
Set colEvents = objWMIService.ExecNotificationQuery(Query)
Do
Set objEvent = colEvents.NextEvent
Wscript.Echo objEvent.Path_.Class
If objEvent.TargetInstance.DriveType = 2 Then
if objEvent.Path_.Class = "__InstanceCreationEvent" then
Wscript.Echo "Drive " & _
objEvent.TargetInstance.DeviceId & _
" が追加されました"
end if
if objEvent.Path_.Class = "__InstanceDeletionEvent" then
Wscript.Echo "Drive " & _
objEvent.TargetInstance.DeviceId & _
" が削除されました"
End if
End If
Loop
|