Write a script to run a service upon reboot

Write a script to run a service upon reboot

avatar

Hello fellos,

I like to write a script to run a service upon reboot regardless which user is logged. I managed to find something below that creates a task in Win scheduler.

@echo off
for %%C in (server name) do (
schtasks /Create /F /S %%C /RU "System" /SC OnStart /TN StartSvc /TR "C:\Windows\System32\sc.exe start """service name with space"" /delay 0005:00
)

The next task is to add in credential into it, which I have trouble getting to it. The service does not auto run without credentials. How do I write the script with user name and password embedded? Any pointers

All Comments (1)

avatar

Hello,

Thank you for your feedback.

What DVLS version are you using?

The following Microsoft online help page provides information on embedding credentials with the schtasks /Create command.
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks-create

Let us know if that helps.

Best regards,

Érica Poirier