+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, VBS Script - Can this script please be editted to close after it triggers? in Coding and Web Development; This VBS script below detects when Outlook.exe is loaded and then triggers another script to load. It currently works perfectly ...
  1. #1

    Join Date
    Aug 2007
    Posts
    818
    Thank Post
    101
    Thanked 65 Times in 47 Posts
    Rep Power
    26

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

    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


    Code:
    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

  2. #2

    Join Date
    Mar 2011
    Location
    Bournemouth
    Posts
    280
    Thank Post
    16
    Thanked 74 Times in 64 Posts
    Rep Power
    22
    Dont need the infinite loop, NextEvent waits for the next event...

    Code:
    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"

  3. Thanks to ChrisMiles from:

    burgemaster (21st November 2012)

  4. #3

    Join Date
    Aug 2007
    Posts
    818
    Thank Post
    101
    Thanked 65 Times in 47 Posts
    Rep Power
    26
    Of course!
    Works perfectly

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 1st June 2012, 04:25 PM
  2. Replies: 14
    Last Post: 17th June 2010, 10:57 PM
  3. Double check this script please
    By FN-GM in forum Scripts
    Replies: 1
    Last Post: 28th May 2008, 10:41 PM
  4. Replies: 21
    Last Post: 11th July 2006, 07:37 PM
  5. can this be done?
    By beeswax in forum Windows
    Replies: 6
    Last Post: 23rd June 2006, 09:30 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •