home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileBin002 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  5.3 KB  |  83 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        AutoRestart.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Run from within a user profile to look for a specific 
  6. ' ***                program and start it if it is not already running.
  7. ' *** ------------------------------------------------------------------------------
  8. ' *** Version:        1.0
  9. ' *** Notes:        
  10. ' *** ------------------------------------------------------------------------------
  11. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  12. ' *** ------------------------------------------------------------------------------
  13. ' ***
  14.  
  15. ' ~~~ 
  16. ' ~~~ Force variables to be declared. Turn off errors
  17. ' ~~~ 
  18. Option Explicit
  19. On Error Resume Next
  20.  
  21. ' ***
  22. ' *** ------------------------------------------------------------------------------
  23. ' *** Name:        Main
  24. ' *** ------------------------------------------------------------------------------
  25. ' *** Purpose:        Loop indefinitely, checking for the application every 5 sec.
  26. ' *** ------------------------------------------------------------------------------
  27. ' ***
  28.  
  29. Dim oShell, oWMI, strAppName
  30.  
  31. Set oShell = CreateObject("Wscript.Shell")
  32. Set oWMI   = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  33.  
  34. strAppName = ""
  35. strAppName = Wscript.Arguments(0)
  36.  
  37. If strAppName = "" Then Wscript.Quit
  38.  
  39. Do While True
  40.     RunApp
  41.     Wscript.Sleep(5000)
  42. Loop
  43.  
  44.  
  45. ' ***
  46. ' *** ------------------------------------------------------------------------------
  47. ' *** Name:        IsAppRunning
  48. ' *** ------------------------------------------------------------------------------
  49. ' *** Purpose:        Look to see if the application is running
  50. ' *** ------------------------------------------------------------------------------
  51. ' ***
  52. Function IsAppRunning
  53.     On Error Resume Next
  54.  
  55.     Dim colProcesses, oProcess
  56.     
  57.     Set colProcesses = oWMI.ExecQuery("SELECT * FROM Win32_Process")
  58.  
  59.     IsAppRunning = False
  60.  
  61.     For Each oProcess in colProcesses
  62.         If UCase(oProcess.ExecutablePath) = UCase(strAppName) Then
  63.             IsAppRunning = True
  64.         End If
  65.     Next
  66. End Function
  67.  
  68. ' ***
  69. ' *** ------------------------------------------------------------------------------
  70. ' *** Name:        RunApp
  71. ' *** ------------------------------------------------------------------------------
  72. ' *** Purpose:        If the application is not running, start it!
  73. ' *** ------------------------------------------------------------------------------
  74. ' ***
  75. Sub RunApp
  76.     On Error Resume Next
  77.  
  78.     If NOT IsAppRunning Then
  79.         oShell.Exec strAppName
  80.         WScript.sleep 5000
  81.     End If
  82. End Sub
  83.