I have a service which I want to have started with a specific priority assigned to the executable. This has been difficult so far but what I’ve done is set up a scheduled task which uses cscript.exe to launch a vbs file. This VBS file will then launch a bat file that checks to see if the service is running and if not, it will launch it with net start. The purpose of the vbs file is to launch the service with no console. I don’t want that popping up every 5 minutes. Afterward it would call wmic to set the priority on the executable.
Here is the scheduled task:
As you can see this service is set to run at startup then repeat every 5 minutes. Each time if the service is not running it should start it again with net start then set the priority.
The first issue is that executing this task accomplishes nothing. At least when I execute it from the Task Scheduler. The second is that even if this did start the service, which I can do manually by way of an administrator level cmd, the service becomes entirely unresponsive to SCM. I cannot stop/restart the process. It will invariably give me the following message. I have to kill the executable through task manager.
The objective here is fairly simple.
- Start a service if it is not running
- Set the priority on the service to some elevated state.
- Allow the service to be controlled via SCM while doing the above.
What am I doing wrong here? I assume the admin privileges have something to do with why I can successfully start the service via cmd but not Task Scheduler, and I assume that there is some issue with STDOUT or something being redirected that interferes with service as it pertains to SCM. Please help me out here!
For reference, here is the content of the vbs and bat file:
StartNoConsole.vbs:
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c ""C:Program Files (x86)SteamsteamappscommonSpaceEngineersDedicatedServerDedicatedServer64Start.bat"""
oShell.Run strArgs, 1, false
Start.bat
for /F "tokens=3 delims=: " %%H in ('sc query "City of Rats" ^| findstr " STATE"') do (
if /I "%%H" NEQ "RUNNING" (
net start "City of Rats"
wmic process where name="SpaceEngineersDedicated.exe" CALL setpriority "Realtime"
)
)