0

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.

rawatdeepesh
  • 584
  • 8
  • 31

1 Answers1

1

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)
Community
  • 1
  • 1
ScriptKidd
  • 803
  • 1
  • 5
  • 19
  • thanks, I can't create a scheduled task since the server security policy won't let me do that (not able to save password) and the job needs to be done by a user that is not logged in. So I am creating a service that performs the job, and the Log-On could be changed to this user. The conversion of batch script such that it creates a service is the issue as of now. – rawatdeepesh Feb 18 '20 at 05:22