×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Check if program is running and if not, start program

Check if program is running and if not, start program

Check if program is running and if not, start program

(OP)
I've never written a script in my life, but have been asked to write one to check if a program is running and if it isn't, run the program.

Back story: We have a program called tcp-wedge that monitors our fire panel system. The other day it did not send an alert. It turned out the tcp-wedge software that was supposed to send the email wasn't running.

I've Googled the heck out of this and don't understand what I'm reading. There are tons of posts about scripts for checking if processes are running.

Could someone help me out here?

We'd like it to check once an hour if the program is running and if it's not, run the program.

Thanks for any help.

RE: Check if program is running and if not, start program

Well here are some of the things you need to do

1. Determine where the script is going to run. If it's not on the server that has the software running, then you need to make sure you can connect to it remotely (WinRM).
2. Find the name of the executable, so you know what should be running
3. Write the script
4. Test the script
5. Run script as a scheduled task

There are several on here that are willing to assist with fixing logic/syntax, but I don't know if anyone would be willing to write the script for you. I understand that you're new to scripting, we've all been there, but you need to give it a shot and then come back with something we can work from (give a man a fish vs teaching him to fish).

Don't get discouraged.


Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Check if program is running and if not, start program

(OP)
Thank you for the encouragement. After beating my head against the wall for an entire day, I took a day off from trying to figure it out. Today I tried again and found a script.

One issue though, when it runs, if the tcp software is running, it will open another occurrence.

Here is the script that is kind of working:

tasklist | findstr -i Fire Panel Config.TW3

if %errorlevel% NEQ 1 goto end
rem ^^^^^^^^^^^^^^^^^^^^^^^^^ If TCPWedge is running (then errorlevel is Not EQual to 1) goto end?
cmd /c dir && "C:\TCPWedge Configs\Fire Panel Config\Fire Panel Config.TW3"
timeout /t 60

:end

I found a forum that said it had something to do with the if %errorlevel% NEQ 1 goto end and that the original poster had a 0 instead of 1. As you can see I changed mine to a 1 and it still opens duplicates.

Any idea why? I'm just so happy I even found a script that will open the app. That was half the battle...

RE: Check if program is running and if not, start program

How about this?

CODE -->

$app = "Fire Panel Config.TW3"
$path2exe = "C:\TCPWedge Configs\Fire Panel Config\Fire Panel Config.TW3"
$running = tasklist.exe | findstr -i $app
if (!$running)
{cmd /c $path2exe}


Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Check if program is running and if not, start program

(OP)
Sorry I haven't responded, been kinda busy putting out other fires. Your script was extremely helpful. Thank you so much.

RE: Check if program is running and if not, start program

(OP)
I have another problem though...the script works, but this process also runs in the background. So, the application is closed, but since it's running in the background, it doesn't open the application.
I went to task manager and it showed it was running in the background processes. Any way I can make it ignore background processes?

RE: Check if program is running and if not, start program

(OP)
Since I got tired of fighting with this, I contacted the software company. The resolution was they gave me a newer version of the software that doesn't run in the background and they were nice enough to give me a little VB program that checks every 5 seconds if the program is running and if it isn't opens it.

The powershell script would probably work now too since this program is no longer running in the background.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close