home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: AutoRestart.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Run from within a user profile to look for a specific
- ' *** program and start it if it is not already running.
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared. Turn off errors
- ' ~~~
- Option Explicit
- On Error Resume Next
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Main
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Loop indefinitely, checking for the application every 5 sec.
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- Dim oShell, oWMI, strAppName
-
- Set oShell = CreateObject("Wscript.Shell")
- Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
-
- strAppName = ""
- strAppName = Wscript.Arguments(0)
-
- If strAppName = "" Then Wscript.Quit
-
- Do While True
- RunApp
- Wscript.Sleep(5000)
- Loop
-
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: IsAppRunning
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Look to see if the application is running
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function IsAppRunning
- On Error Resume Next
-
- Dim colProcesses, oProcess
-
- Set colProcesses = oWMI.ExecQuery("SELECT * FROM Win32_Process")
-
- IsAppRunning = False
-
- For Each oProcess in colProcesses
- If UCase(oProcess.ExecutablePath) = UCase(strAppName) Then
- IsAppRunning = True
- End If
- Next
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: RunApp
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: If the application is not running, start it!
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub RunApp
- On Error Resume Next
-
- If NOT IsAppRunning Then
- oShell.Exec strAppName
- WScript.sleep 5000
- End If
- End Sub
-