Board logo

标题: [转贴] VBS检测可移动磁盘的连接与断开 [打印本页]

作者: tmplinshi    时间: 2011-7-31 17:18     标题: VBS检测可移动磁盘的连接与断开

  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  3. Set colEvents = objWMIService.ExecNotificationQuery _
  4.     ("Select * From __InstanceOperationEvent Within 10 Where " _
  5.         & "TargetInstance isa 'Win32_LogicalDisk'")
  6. Do While True
  7.     Set objEvent = colEvents.NextEvent
  8.     If objEvent.TargetInstance.DriveType = 2 Then
  9.         Select Case objEvent.Path_.Class
  10.             Case "__InstanceCreationEvent"
  11.                 Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _
  12.                     " has been added."
  13.             Case "__InstanceDeletionEvent"
  14.                 Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _
  15.                     " has been removed."
  16.         End Select
  17.     End If
  18. Loop
复制代码
转自: http://blogs.technet.com/b/heysc ... gets-connected.aspx
作者: BillGates    时间: 2011-7-31 20:10

不错,支持一下。
作者: Hello123World    时间: 2011-8-1 16:51

犀利啦,这都看的懂。——这英语得多少级啊!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2