Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AzureDevOps commandline as administrator

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

like image 738
miechooy Avatar asked Jun 13 '26 04:06

miechooy


1 Answers

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.

like image 139
Kevin Lu-MSFT Avatar answered Jun 17 '26 10:06

Kevin Lu-MSFT