批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[转贴] 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

不错,支持一下。

TOP

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

TOP

返回列表