2008-10-05 61 views

回答

1

好吧..發現我一直在尋找:)

在這個VBScript中看看:(source):

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 

Set colEvents = objWMIService.ExecNotificationQuery _ 
    ("Select * From __InstanceOperationEvent Within 10 Where " _ 
     & "TargetInstance isa 'Win32_LogicalDisk'") 

Do While True 
    Set objEvent = colEvents.NextEvent 
    If objEvent.TargetInstance.DriveType = 2 Then 
     Select Case objEvent.Path_.Class 
      Case "__InstanceCreationEvent" 
       Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _ 
        " has been added." 
      Case "__InstanceDeletionEvent" 
       Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _ 
        " has been removed." 
     End Select 
    End If 
Loop 

我把它留給你的運動將它移植到C#。

不是一直在輪詢您可以使用WMI event sink

相關問題