This is the code I am using. It is something I found on other posts on this site.
- Script Code #1:
@ECHO OFF
SET EXEName=TcpSnd.exe
SET EXEFullPath=D:\ComputerRX\Pharmacy\TcpSnd.exe
SET PervasiveName=Pervasive.lnk
SET PervasiveFullPath=C:\Users\Pharmacy\Desktop\Pervasive.lnk
TASKLIST | FINDSTR /I "%EXEName%"
IF ERRORLEVEL 1 GOTO :StartPervasive
IF ERRORLEVEL 0 GOTO :EOF
:StartPervasive
START "" "%PervasiveFullPath%"
GOTO :EOF
The aim of this is to check to see if an important process is active. If the process isn't active, it starts a shortcut with admin privileges that leads to a batch file provided by my software company. The batch provided by my software company closes out their entire suite and then restarts it. I am basically using that one process as a surrogate endpoint to indicate whether the entire suite is functional. I have this scheduled to run once daily in the early morning while we are closed.
I've tested this.
I tested just the first bit, where it checks if the process if active. In the test, rather than starting %PervasiveFullPath%
, I had it just print that the process was inactive.
- Test Code #1:
@ECHO OFF
SET EXEName=TcpSnd.exe
SET EXEFullPath=D:\ComputerRX\Pharmacy\TcpSnd.exe
TASKLIST | FINDSTR /I "%EXEName%"
IF ERRORLEVEL 1 GOTO :StartPervasive
echo TcpSnd.exe Detected...
timeout 3 >NUL
echo This window will now close.
timeout 2 >NUL
GOTO :EOF
:StartPervasive
echo TcpSnd.exe Not Detected
timeout 3 >NUL
echo This window will now close.
timeout 2 >NUL
GOTO :EOF
And it worked.
I then tested the second segment.
- Test Code #2:
@ECHO OFF
SET PervasiveName=Pervasive.lnk
SET PervasivePath=C:\Users\Pharmacy\Desktop\Pervasive.lnk
:StartPervasive
echo TcpSnd.exe Not Detected
timeout 2 >NUL
echo Restarting Pervasive...
START "" "%PervasivePath%"
timeout 3 >NUL
echo Please Stand By...
timeout 7 >NUL
echo This window will now close.
timeout 2 >NUL
GOTO :EOF
And it worked.
I tested the whole thing and it worked.
I've confirmed with my software company that their batch is fine and mine seems to work, too.
Finally, I tried to test it by running it from Task Scheduler. That is where problems start to arise.
I have it set as Run whether user is logged in or not, run with highest privileges, configured for Windows 10, the file location of the batch file under Program/script, Allow task to be run on demand, Run task as soon as possible after a scheduled start is missed, and Do not start a new instance if the task is already running.
If I close TcpSnd.exe
and then run the task from Task Scheduler, half of my software provider's batch file runs, but then it stops randomly. It shuts down the full suite of programs, but just stops before it reopens them. This doesn't happen if I use my batch to trigger their batch or just trigger their batch directly.
Edit 1:
Adding my software provider's batch, but I scrubbed it of specific targets just so I don't accidentally violate some unknown part of my license agreement.
- Software Provider's Code:
@echo off
del [background exe] /s /f
taskkill /f [/im [program in suite] repeated around 30 times]
timeout /t 5 /nobreak
net start "Pervasive.SQL (relational)"
net start "Pervasive.SQL (transactional)"
timeout /t 5 /nobreak
net start [Service name 1]
net start [Service name 2]
cd\
d:
cd computerrx\pharmacy
start primaryprogram1.exe
start primaryprogram2.exe
start primaryprogram3.exe
start primaryprogram4.exe
start primaryprogram5.exe
start primaryprogram6.exe
rem start unusedprogram1.exe
rem start unusedprogram2.exe
rem start unusedprogram3.exe
rem start unusedprogram4.exe
rem start unusedprogram5.exe
rem start unusedprogram6.exe
timeout /t 5 /nobreak
taskkill /f /im [lastprogram].exe
start [lastprogram].exe
exit
Images of Task settings:
- General:
- Triggers:
- Actions:
- Edit Actions:
- Conditions:
- Settings:
Edit 2:
I've done some experimenting. I separated this into two different tasks. One that logs an event at a given time if the tspsnd.exe process isn't running and the other that looks for and responds to the event by triggering the second batch file directly. It runs into the same issue.
For that second batch file, I've also tried having the task start command prompt with an argument to start the batch file. Runs into the same issue. I've tried changing the task from being run under my account with full admin privileges to being run under System and ran into the same problem. I've also tried changing the permissions on the folder with the second batch to explicitly include my user account and also ran into the same problem.
According to my event viewer, the hold up is the net start commands after the list of processes to kill and before the .exe's are started. Each time I run the batch from Task Scheduler, those processes fail to initialize with an Event 7034, Service Control Manager error.
Pervasive.lnk
do? What is the "software provider's batch file"?.lnk
file, instead of what it points to?