3

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

miechooy
  • 3,178
  • 12
  • 34
  • 59

1 Answers1

5

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.

agent

Here is a doc about create agent.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28