1

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:
    General

  • Triggers:
    Triggers

  • Actions:
    Actions

  • Edit Actions:
    Edit Actions

  • Conditions:
    Conditions

  • Settings:
    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.

13
  • 1
    What does Pervasive.lnk do? What is the "software provider's batch file"?
    – harrymc
    Commented Mar 8 at 16:51
  • Pervasive.lnk is a shortcut with admin privileges that opens the software provider's batch file. The software provider's batch file systematically closes and then reopens their software suite. It just kills some 30+ processes and then reopens 6 or so programs. Honestly not sure if posting their file would be allowed. I can confirm that it works, though, so it likely isn't the problem in and of itself.
    – RPhZach
    Commented Mar 8 at 17:02
  • 1
    We have no idea what it does exactly and where it fails, as you haven't included it. And why do you run a .lnk file, instead of what it points to?
    – harrymc
    Commented Mar 8 at 17:05
  • Okay, updated the original post. Scrubbed it of specifics just so I don't get my license revoked. I tried using their batch directly, but half of the actions failed because it lacked admin privileges. The shortcut has those permissions.
    – RPhZach
    Commented Mar 8 at 17:25
  • If it needs administrator permissions, ensure that the scheduled task is set to run with the highest privileges.
    – harrymc
    Commented Mar 8 at 17:59

1 Answer 1

0

I managed to get it to work. From reading other posts, I learned that CMD doesn't show if you have "Run whether user is logged on or not" and only does so when you have "Run only when use is logged on" checked. Once I did that, everything worked as it should have.

The final form of the code I used was:

Script Code #2

@ECHO OFF

SET EXEName=TcpSnd.exe
SET EXEFullPath=D:\ComputerRX\Pharmacy\TcpSnd.exe

TASKLIST | FINDSTR /I "%EXEName%"
IF ERRORLEVEL 1 GOTO :StartPervasive
IF ERRORLEVEL 0 GOTO :EOF

:StartPervasive
eventcreate /l application /so "RxBatchLog" /t information /id 1000 /d "Pharmacy suite is not running."
GOTO :EOF

The second batch is triggered by a scheduled task that looks for that event log.

General

Edit Trigger

Edit Action

I had the task launch CMD and then used

"/c D:\ComputerRX\Pharmacy\AppPCCServReStart"

to start the software provider's batch file.

I already had my account set to automatically login upon reboot using control userpasswords2, so I won't need to have the task force a logon.

1
  • The solution shall be in the answer, not in the question. I have moved it for you. Please review, check if nothing is missing. Commented Mar 11 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .