Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS Script Assistance 4

Status
Not open for further replies.

Pleonasm

Technical User
May 20, 2004
121
0
0
CA
I am seeking a sample VBS script for Windows XP that checks to see if a process is currently running (e.g., "taskmgr.exe") and, if it is not running, then launches a program (e.g., "C:\Windows\Notepad.exe").

Thank you for your assistance.
 
You could use something like the following:

Code:
Dim WSH
Set WSH = WScript.CreateObject("WScript.Shell")

Set locator = CreateObject("WbemScripting.SWbemLocator")
Set service = locator.ConnectServer()
Set props = service.ExecQuery("select name, description from Win32_Process where name = 'taskmgr.exe'")
num = props.Count

If num > 0 Then
   'Program is running
   WSH.Run "C:\Windows\Notepad.exe"
Else
   'Program is not running
   WSH.Popup "Program is not running"
End If

Set WSH = Nothing

Hope this helps...
 
Rick998
This script is neet. I replaced 'taskmgr.exe' with 'FahCore_78.exe. I also created a text file called 'C:\Folding@Home\Folding_DNA.txt' (weird but the file name doesn't like spaces)

:) The txt file says.... "Folding DNA!!!"

I run Folding@Home on multi PCs and this works great!
 
You would need to include the file name within quites to use spaces.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top