我在 vbs 文件中有以下代码:Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")设置 colMonitoredEvents = objWMIService.ExecNotificationQuery _("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE _目标实例 ISA 'CIM_DirectoryContainsFile' 和 TargetInstance.GroupComponent='Win32_Directory.Name=""P:\\\\Folder1\\\\Folder2\\\\Folder3\\\\CURRENT_YEAR"""'")做'如果找到文件夹中的文件则执行的代码环形 解决方案 在 vbscript 中你可以得到这样的年份:CURRENT_YEAR=年(现在)MsgBox CURRENT_YEARMsgBox "P:\\\\Folder1\\\\Folder2\\\\Folder3\\\\"&CURRENT_YEAR &""CURRENT_YEAR=年(现在)sPath = "F:\Folder1\Folder2\Folder3\"&今年sDrive = split(sPath,":")(0)sFolders1 = split(sPath,":")(1)sFolders = REPLACE(sFolders1, "\", "\\\\")TargetFolder = DblQuote(sDrive & ":& sFolders)wscript.echo 路径wscript.echo 目标文件夹strComputer = ."Set objWMIService = GetObject("winmgmts:" _&"{impersonationLevel=impersonate}!\\"&_strComputer &\root\cimv2")设置 colMonitoredEvents = objWMIService.ExecNotificationQuery _("Select * From __InstanceCreationEvent Within 2 Where " _&"Targetinstance Isa 'CIM_DirectoryContainsFile' 和 "_&TargetInstance.GroupComponent="_&"'Win32_Directory.Name="&目标文件夹 &"'")' 循环做设置 objLatestEvent = colMonitoredEvents.NextEventWscript.Echo objLatestEvent.TargetInstance.PartComponent环形'-------------------------------------------------------------函数 DblQuote(str)DblQuote = chr(34) &Str &铬(34)结束函数'-------------------------------------------------------------How can I put the current year in CURRENT_YEAR so the folder I am monitoring is P:\\\\Folder1\\\\Folder2\\\\Folder3\\\\2020I have the following code in a vbs file:Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE _Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent= 'Win32_Directory.Name=""P:\\\\Folder1\\\\Folder2\\\\Folder3\\\\CURRENT_YEAR""'")Do'code to execute if file in folder foundLoop 解决方案 In vbscript you can get the year like this :CURRENT_YEAR=Year(Now)MsgBox CURRENT_YEARMsgBox "P:\\\\Folder1\\\\Folder2\\\\Folder3\\\\"& CURRENT_YEAR &""CURRENT_YEAR=Year(Now)sPath = "F:\Folder1\Folder2\Folder3\"& CURRENT_YEARsDrive = split(sPath,":")(0)sFolders1 = split(sPath,":")(1)sFolders = REPLACE(sFolders1, "\", "\\\\")TargetFolder = DblQuote(sDrive & ":" & sFolders)wscript.echo sPathwscript.echo TargetFolderstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * From __InstanceCreationEvent Within 2 Where " _ & "Targetinstance Isa 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name="& TargetFolder &"'")' The loopDo Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo objLatestEvent.TargetInstance.PartComponentLoop'-------------------------------------------------------------Function DblQuote(str) DblQuote = chr(34) & str & chr(34)End Function'------------------------------------------------------------- 这篇关于如何在VBS中的WMI服务查询中使用变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 06:30