Jump to content

VBS Script - Can this script please be editted to close after it triggers?


Recommended Posts

Posted

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

Posted

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"

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...