1

我的 vb 宏监视文件夹路径以创建新文件。我可以监视本地驱动器中的路径。如何提供网络驱动器的路径???

下面是我的代码。这里 strDirToMonitor 是我需要提供网络路径(\share\files)的地方

但是 \ 不工作..

strComputer = "."
strDirToMonitor = "c:\\\\test"
'// Monitor Above every 10 secs...
strTime = "10"

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

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN " & strTime & " WHERE " _
    & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
        & "TargetInstance.GroupComponent= " _
            & "'Win32_Directory.Name=" & Chr(34) & strDirToMonitor & Chr(34) & "'")
4

1 回答 1

0

网络路径指定如下:\\COMPUTUER_NAME\SHARE\PATH. 显然,您需要像使用本地路径一样转义(加倍)反斜杠

但是,您可以对网络和本地路径执行的操作存在一些差异,因为远程路径不受本地计算机控制 - 所以我不确定您尝试完成的操作是否有效。

编辑:正如评论中所讨论的......

strComputer = "CompB"
strDirToMonitor = "c:\\\\test"
'// Monitor Above every 10 secs...
strTime = "10"

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

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN " & strTime & " WHERE " _
    & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
        & "TargetInstance.GroupComponent= " _
            & "'Win32_Directory.Name=" & Chr(34) & strDirToMonitor & Chr(34) & "'")
于 2012-08-30T06:30:20.037 回答