I would like to stop Topshelf service using cmd task in azure devops release pipeline. What I do is create CommandLineTask which following script:
ServiceName.exe stop
As an output I see
v3.1.4 2020-06-05T10:14:20.1312163Z The ServiceName service can only be stopped by an administrator
My question is if there is a way to run this CommandLineTask as an administrator?
PS. I use agent on my virtual machine where the service exist itself
Since you are using the self-hosted agent, you could try to use the administrator account (Local system admin) to create and run the agent.
For interactive mode self-hosted agent:
You could use the following command to create an agent with admin account.
.\config.cmd --unattended --url https://myaccount.visualstudio.com --auth pat --token myToken --pool default --agent myAgent --runAsAutoLogon --windowsLogonAccount myDomain\adminaccount --windowsLogonPassword Password
For service mode self-hosted agent:
On one hand, you could create an agent with the admin account(similar as interactive mode).
.\config.cmd --unattended --url https://myaccount.visualstudio.com --auth pat --token myToken --pool default --agent myAgent --runAsService --windowsLogonAccount myDomain\adminccount --windowsLogonPassword Password
On the other hand, you could navigate to local system -> Service and find the running agent service.
Then you could change the logon account as admin account.

Here is a doc about create agent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With