我认为问题在于您没有将查询中的 \ 字符加倍。\ 是 WQL 中的保留字符,因此您必须改用 \。下面是我使用的 VBScipt 并且能够开始工作。我希望这是有帮助的!
Main
Sub Main()
WScript.Echo "Initializing WMI..."
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & _
strComputer & "\root\CIMV2")
Set EventSink = WScript.CreateObject( _
"WbemScripting.SWbemSink","SINK_")
WScript.Echo "WMI Initialized."
query = "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'CIM_DataFile' AND TargetInstance.Path='\\data\\'"
WScript.Echo "Executing Query..."
set results = objWMIservice.ExecNotificationQuery(query)
WScript.Echo "Query Returned."
Do
WScript.Echo "Waiting on events..."
Set evt = results.NextEvent
WScript.Echo "Modified Path:" + evt.TargetInstance.Path
WScript.Echo "Modified Path:" + evt.TargetInstance.Name
Loop
End Sub
您可能也有兴趣通过一些 .NET 语言(例如 VB.NET 或 C#)使用FileSystemWatcher来做同样的事情。