rawatdeepesh
rawatdeepesh

Reputation: 584

service to perform scheduled task operation

Is it possible to create a Windows Scheduled Task from a Windows batch file with another batchfile as a parameter:

For eg : schtasks.exe /create /tn "taskName" /tr "%Home%\bin\bootstrap.cmd" /sc DAILY /st 00:01:00 /ri 1 /du 0023:59 %schTaskAccountArgs%"

Background
The batch file 'bootstrap.cmd' in the script above has calls to other batchfiles and eventually an exe. It creates a scheduled task in the Microsoft console which triggers the same exe, but in my case due to a GPO policy, the scheduled task couldn't be created (policy being-not able to store passwords for the user that runs the scheduled job). As a workaround I want to create a service in the same Batch file by replacing the above by:

sc create "service for taskName" start= demand displayname= "service for taskName" binpath= "%Home%\bin\bootstrap.cmd"

is it a feasible method to create a service for this scenario.

Upvotes: 0

Views: 125

Answers (1)

ScriptKidd
ScriptKidd

Reputation: 841

Windows appears to not run .bat (and .cmd) files as services.

Here are some alternatives:

  1. Create a scheduled task that runs at startup.
  2. Convert the .cmd into an executable. See How can a .bat file be 'converted' to .exe without third party tools?
  3. Use external tools (like NSSM featured here)

Upvotes: 1

Related Questions