Script, was mache ich verkehrt?
Hallo zusammen,
ich hoffe mir kann jemand von euch helfen. Ich wollte mit diesen Script 3 Ordner überwachen und bei Eingang soll ein Programm starten. Leider läuft es nicht und ich finde den Fehler nicht
ich hoffe mir kann jemand von euch helfen. Ich wollte mit diesen Script 3 Ordner überwachen und bei Eingang soll ein Programm starten. Leider läuft es nicht und ich finde den Fehler nicht
Const strPath = "D:\A"
Const strPath2 = "D:\B"
Const strPath3 = "D:\C"
Const intInterval = "2"
strDrive = Split(strPath,"\")(0)
strFolder = Replace(Split(strPath,":")(1),"\","\\") & "\\"
strDrive2 = Split(strPath2,"\")(0)
strFolder2 = Replace(Split(strPath2,":")(1),"\","\\") & "\\"
strDrive3 = Split(strPath3,"\")(0)
strFolder3 = Replace(Split(strPath3,":")(1),"\","\\") & "\\"
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set objShell = CreateObject("Wscript.Shell")
Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2" )
strQuery = "Select * From __InstanceOperationEvent" _
& " Within " & intInterval _
& " Where Targetinstance Isa 'CIM_DataFile'" _
& " And ((TargetInstance.Drive='" & strDrive & "'"_
& " And TargetInstance.Path='" & strFolder & "') or "_
& "(TargetInstance.Drive='" & strDrive2 & "'"_
& " And TargetInstance.Path='" & strFolder2 & "')) or"_
& "(TargetInstance.Drive='" & strDrive3 & "'"_
& " And TargetInstance.Path='" & strFolder3 & "')))"
Set colEvents = objWMIService.ExecNotificationQuery (strQuery)
Do
Set objEvent = colEvents.NextEvent()
Set objTargetInst = objEvent.TargetInstance
Select Case objEvent.Path_.Class
Case "__InstanceCreationEvent"
objShell.Run """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
End Select
Loop
Please also mark the comments that contributed to the solution of the article
Content-Key: 307648
Url: https://administrator.de/contentid/307648
Printed on: April 23, 2024 at 09:04 o'clock
2 Comments
Latest comment
Look at the parentheses in your notification query, they are not distributed correctly
Regards
strQuery = "Select * From __InstanceOperationEvent" _
& " Within " & intInterval _
& " Where Targetinstance Isa 'CIM_DataFile'" _
& " And ((TargetInstance.Drive='" & strDrive & "'"_
& " And TargetInstance.Path='" & strFolder & "') or "_
& "(TargetInstance.Drive='" & strDrive2 & "'"_
& " And TargetInstance.Path='" & strFolder2 & "') or"_
& "(TargetInstance.Drive='" & strDrive3 & "'"_
& " And TargetInstance.Path='" & strFolder3 & "'))"