Windows – How to start a service on a remote machine using a different user

serviceswindows

I have the same service running on a dozen test machines. Said service has croaked (specifically, it was shut down and disabled by a test, and the test died halfway through), and I want to re-enable and restart it on all of those machines. The normal solution is sc \\machine config ServiceName start=auto followed by sc \\machine start ServiceName, and it works fine if my user account is authorized on the other machine. But since these are cloned test machines created from a common image that doesn't know me from Adam, they don't recognize me. I know I could go in and authorize myself on those machines, but they get wiped on a fairly regular basis and I'm trying to save some time.

I know the local Administrator password for all of these machines. (And it's the same thing, due to the cloning.) How can I run sc.exe so that it will log in with that user? Or is there another way I can enable and start those services programatically from my machine? (I have a dead-simple looping PowerShell script all ready to go, but it's not much use if I can't find a command to run that will be accepted.)

For reference, here's the error message I'm getting:

[SC] OpenSCManager FAILED 5:

Access is denied.

Best Answer

sc \\machine config ServiceName start= auto obj= Username password= PWD

Related Question