Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Create a task to run exe if it is not running.

3 Weeks Ago   #1
JustWatching

Windows 7 Ultimate x64
 
 
Create a task to run exe if it is not running.

I am trying to figure out how to use task scheduler to open an exe if it is not already running, also trying to get the task to check this every hour or so but all I get is Daily, weekly, etc options.


My System SpecsSystem Spec
.
3 Weeks Ago   #2
townsbg

Windows 7 pro 64-bit sp 1
 
 

I have the option for every hour.

Create a task to run exe if it is not running.-new-task.png


My System SpecsSystem Spec
3 Weeks Ago   #3
F22 Simpilot

Windows 7 Ultimate x64
 
 

You will need to run the .exe as a service. To do this grab NSSM here: NSSM - the Non-Sucking Service Manager


Place the nssm-2.24 folder in the directory folder of the .exe you want to run as a service. (Keep in mind there are two nssm-2.24 folders. You want to copy/paste the nssm-2.24 folder containing the program.

So say you have server.exe as an .exe you want to run as a service, and server.exe is located in
Code:
C:\program files\server
So place the nssm-2.24 folder in
Code:
C:\program files\server\
This is where server.exe is located.

Now go to the start orb and in the search box enter cmd. Right click command prompt and open as administrator.

Once cmd is open enter cd and your path to the exe you want to run as a service. In this case,
Code:
cd C:\program files\server\
this is also the path that has the nssm-2.24 folder.


Now once you cd into that path (cd means change directory by the way) enter
Code:
nssm.exe install [servicename]
.

A service install GUI will pop up. Pick the path to your exe that you want to run as a service. In this case the path is
Code:
C:\program files\server\server.exe
Under the Details tab enter a name for your new service that isn't the same name of a service you have running already and give it a quick description. Under the Exit actions tab you may want to delay the restart by so many milliseconds. Maybe 500 ms for half a second. You can leave all the other options alone.

If done correctly your .exe should start with Windows boot. If it fails it should automatically restart.


I have not tried this program before, so YMMV.

What .exe are you wanting to start with Windows anyway?
My System SpecsSystem Spec
.

3 Weeks Ago   #4
F22 Simpilot

Windows 7 Ultimate x64
 
 

Double post. vBulletin crap as usual.
My System SpecsSystem Spec
3 Weeks Ago   #5
F22 Simpilot

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by townsbg View Post
I have the option for every hour.

Attachment 405987

And after everything I wrote this may be the answer. Ugh
My System SpecsSystem Spec
3 Weeks Ago   #6
JustWatching

Windows 7 Ultimate x64
 
 

I do not want it to start when windows starts.

I want my computer to constantly check if the program is running and if it is not, then run the program. I cannot seem to be able to do this with task scheduler
My System SpecsSystem Spec
3 Weeks Ago   #7
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

I suspect you can do this from the CMD prompt, which means you can probably run a batch file to perform the test and run the program conditionally.

Hint: Use TASKLIST with either /svc or /v switch. For example,
Code:
TASKLIST /FI "imagename eq program.exe" /svc
or
Code:
TASKLIST /v /fi "STATUS eq running"
Here is someone with a similar question to yours: Batch - check If program is running , if not , run it - Stack Overflow
My System SpecsSystem Spec
3 Weeks Ago   #8
JustWatching

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by iko22 View Post
I suspect you can do this from the CMD prompt, which means you can probably run a batch file to perform the test and run the program conditionally.

Hint: Use TASKLIST with either /svc or /v switch. For example,
Code:
TASKLIST /FI "imagename eq program.exe" /svc
or
Code:
TASKLIST /v /fi "STATUS eq running"
Here is someone with a similar question to yours: Batch - check If program is running , if not , run it - Stack Overflow

Ok that batch file should work, but how do I get windows to run it every hour?
My System SpecsSystem Spec
3 Weeks Ago   #9
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

To get a batch file to run every hour, you would need to add either TIMEOUT or PING to the batch file, and then put the batch file into a loop. One hour is 60 minutes * 60 seconds = 3600 seconds.

TIMEOUT waits so many seconds, and then continues executing the batch file. Problem is that a keypress can interrupt the timeout. So, best use PING. For example PING -n 3600 127.0.0.1>nul gives a timeout of 3600 echo requests.
My System SpecsSystem Spec
3 Weeks Ago   #10
JustWatching

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by iko22 View Post
To get a batch file to run every hour, you would need to add either TIMEOUT or PING to the batch file, and then put the batch file into a loop. One hour is 60 minutes * 60 seconds = 3600 seconds.

TIMEOUT waits so many seconds, and then continues executing the batch file. Problem is that a keypress can interrupt the timeout. So, best use PING. For example PING -n 3600 127.0.0.1>nul gives a timeout of 3600 echo requests.

I thought for sure I could set task scheduler to run it every hour but all I get is day, month, etc
My System SpecsSystem Spec
Reply

 Create a task to run exe if it is not running.




Thread Tools




Similar help and support threads
Thread Forum
task in task scheduler test running never completes?
I created a batch file. it works fine, opens command prompt runs the task, then it exits. I set the task up in task scheduler. There is a run button, when run it goes from ready to running and never stops... I can select end. The task simply takes 7 seconds when I run it as clicking on the batch...
General Discussion
Task Scheduler - Create Task to Display a Message Reminder
How to Display a Message Reminder in Windows with Task Scheduler This will show you how to create yourself, or another user or group, a message reminder scheduled to display for when and how often you like in Windows 7 or Vista using Task Scheduler. All users on the computer will be able to...
Tutorials
Task Scheduler : Create Shut Down PC Automatically Task
How to Create a Task that will Shut Down the PC Automatically This will show a very easy way to create a task in the Task Scheduler that will shut down the PC whenever you like. This will work for Windows 7 and Windows Vista. Let's get started! 1) In the Windows start menu search box type...
Tutorials
Task Scheduler: running skipped task when it shouldn't?
I have a secondary computer in the network, which is supposed to stay in sleep mode most of the time. I always wake it up when necessary and put it back to sleep when it is no longer needed. I don't want it to fall asleep by itself during the day, so I set the sleep time to "Never" in Power...
General Discussion
Can't create a task in task scheduler, account unknown.
"Task scheduler cannot create the task. The user account is unknown, the password is incorrect, or the user account does not have permission to create this task." I'm getting that message. I read you needed a passworded account to create a task, so I made a new account because I didn't want a...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 13:53.
Twitter Facebook Google+