burgemaster Posted November 21, 2012 Posted November 21, 2012 This VBS script below detects when Outlook.exe is loaded and then triggers another script to load. It currently works perfectly but... if outlook is closed and then re-opened the script runs again. Could someone please advise how it could be modified to close after it detects outlook and launches the script. Somehow get it out of the loop? Thanks in advance Set objShell = CreateObject("Wscript.Shell") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("Select * from __InstanceCreationEvent " _ & " Within 1 Where TargetInstance ISA 'Win32_Process' AND " & _ "TargetInstance.Name = 'Outlook.exe'") Do While True Set objProcess = colMonitoredProcesses.NextEvent objShell.Run "cscript.exe C:\Scripts\Test.vbs" Loop
ChrisMiles Posted November 21, 2012 Posted November 21, 2012 Dont need the infinite loop, NextEvent waits for the next event... Set objShell = CreateObject("Wscript.Shell") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("Select * from __InstanceCreationEvent " _ & " Within 1 Where TargetInstance ISA 'Win32_Process' AND " & _ "TargetInstance.Name = 'Outlook.exe'") Set objProcess = colMonitoredProcesses.NextEvent objShell.Run "cscript.exe C:\Scripts\Test.vbs" 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now