I have an existing Windows service on a remote machine.
Here is what I need to do:
My problem:
I keep getting the following error:
[SC] OpenSCManager FAILED 5:
Access is denied.
@Daniel Mann asked the right question.
First of all,
sc STOP $(serviceName)
should have been a red flag.
@Daniel Mann asked:
Does the service account that your agent is running under have appropriate permissions [to do this]?
But one should also ask:
Which machine are you looking to execute this against? The build agent?
This was, in fact, my problem. When I tested this release pipeline the first time, the target machine and the build agent just happened to be the same machine.
This was an unfortunate accident, because this was not to be the case for all releases.
Solution:
This is correct:
sc \\$(serviceMachine) STOP $(serviceName)
And @Daniel Mann was correct: