Friday, November 8, 2019

Create batch file to check if a process is running and run it hidden

If you want to check if a process is running for specified time and if doesn't run you want to make it start automatically. Here's what you're gonna do :

1. First make a batch file, copy paste these scripts and do some modification depending on your needs :

@echo off
tasklist /FI "imagename eq smartbillingclient.exe" 2>NUL | find /I /N "no tasks are running">NUL
if "%errorlevel%"=="0" (
    start "" "d:\new folder\smartbillingclient.exe"
) else (
    echo Task Found
)
exit

Note :
- smartbillingclient.exe is the name of the process you want to check
- "d:\new folder\smartbilling.exe" is the full path of the process 
- You can change "echo Task Found" with "exit" command

2. Make a schedule for the batch file in task scheduler, just type taskschd.msc in run box.

3. Then create basic task by clicking "Create Basic Task.." in right side panel.

4. "Create Basic Task Wizard" window will pop up, type whatever name you want. For this example: test. Click next to go to next setting.


 5. Choose when do you want the task to start. For this example, i choosed "When I log on" because i want the batch file runs after i log on to the windows. Click next to go to the next setting.
6. Choose "Start Program" in "What action do you want the task to perform" section. Click next to go to next setting.
7. In "Start Program" section, click browse.. and add your batch file full path. Click next to go to next setting.
8. Check "Open the Properties Dialog..", then click finish.
9. A new properties window will pop up, choose "Run whether user is logged on or not", check "Do not store password", "Run with highest privileges" and "Hidden". You can choose what windows you're using in "Configure for :".
10. Go to "Triggers" tab, then click "Edit...". "Edit Trigger" window will pop up, check "Repeat Task Every :" option then type the interval you want for the task to be run. Choose "Indefinitely" in "For a duration of :". You can set delay for the task too.
11. Lastly, go to "Settings" tab, and uncheck "Stop the task if it runs longer than :" option.

No comments:

Post a Comment