Windows – Install Windows service (exe) using cmd with start parameter

servicewindows

How do I install an exe as a windows service with start parameters?
I'm using sc.exe CREATE but can't find how to add start parameters to it.

I've also tried using nssm but can't find how to set start parameters there either.

Everything has to be done using the command prompt

I'm currently trying to use:

sc CREATE test binPath= "\"C:\a.exe\" --run -c \"C:\a.config"

But when trying to run it I get: The service did not respond to the start or control request in a timely fashion.

Best Answer

Not all exe files can be run as services. It's not like an autorun. For example CALC.EXE:

C:\WINDOWS\system32>sc create CALC binpath= "%WINDIR%\system32\calc.exe"
[SC] CreateService SUCCESS

C:\WINDOWS\system32>sc start CALC
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.