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

Page 1 of 2 12 LastLast

  1. Posts : 71
    Windows 7 Ultimate x64
       #1

    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 Computer


  2. Posts : 1,835
    Windows 7 pro
       #2

    I have the option for every hour.

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


  3. Posts : 0
    Windows 7 Ultimate x64
       #3

    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 Computer


  4. Posts : 0
    Windows 7 Ultimate x64
       #4

    Double post. vBulletin crap as usual.
      My Computer


  5. Posts : 0
    Windows 7 Ultimate x64
       #5

    townsbg said:
    I have the option for every hour.

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

    And after everything I wrote this may be the answer. Ugh
      My Computer


  6. Posts : 71
    Windows 7 Ultimate x64
    Thread Starter
       #6

    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 Computer


  7. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #7

    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 Computer


  8. Posts : 71
    Windows 7 Ultimate x64
    Thread Starter
       #8

    iko22 said:
    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 Computer


  9. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #9

    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 Computer


  10. Posts : 71
    Windows 7 Ultimate x64
    Thread Starter
       #10

    iko22 said:
    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 Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 01:25.
Find Us