2008-10-05 43 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

相关问题