2
votes

is there any way to setup the VSTS build agent to run at windows startup in the interactive mode (as an admin)?

Now I'm at the stage where I have installed and configured the agent to run in the interactive mode. So it is running in a console. In the Windows startup there is an entry:

c:\Windows\System32\cmd.exe /D /S /C start "Agent with AutoLogon" "C:\agent\run.cmd" --startuptype autostartup

So without any additional change it is kicked off at Windows startup and it starts in a console. However I need it to run in admin mode so I followed this link:

https://superuser.com/a/1274970

Basicly this one allowed me to setup another cmd.exe that pointed to the original cmd.exe (renamed) and I was able to mark it to run in admin mode. Unfortunately after this change the agent does not start with windows at all.

Is there any way to debug it or see the logs (applications that failed to start)?

Interestingly enough, when I double click on cmd.exe it always starts in admin mode...so there is some blocker on the machine that prevents it to execute the startup command when windows starts.

I've set up the agent to use an account, which is in the Administrators group on the machine. I thought it will start automatically as an admin using the modified cmd that is set up to always start with elevated privileges - It didn't.

Any help greatly appreciated.

Thanks, Chris

2
Have you configured the agent with the .\config option for auto-login using an admin account?Matt
Yes, I have. The funny thing is, when I created a new VM on Azure, installed the agent there, it started working right off the bat. I didn't even have to mess with cmd.exe - it was already set up to run as admin by default.I don't know what happened with the current agent, but I will probably get rid of it and create a new one.Chris4D

2 Answers

3
votes

I ran into the same problem and solved the issue by an entry in the Task Scheduler. The task is set up to Run with highest privileges and is triggered At system startup.

scheduled_task

In combination with UAC set to Never notify, the task shown above runs as an admin and does not trigger user interactions for automated elevations. Note, that the CMD window is not visible since the task runs in the background.

EDIT: If the CMD window needs to run in the foreground one can enable Autologon for the Windows machine and configure the task to Run only when user is logged on.

0
votes

Shortcut solution:

  1. Create a runAgent.cmd file with content:
call "C:\agent\run.cmd" --startuptype autostartup
  1. Create a shortcut runAgent.lnk of runAgent.cmd
  2. For runAgent.lnk open Properties and enable: Shortcut > Advanced... > Run as administrator
  3. Modify the registry key value of VSTSAgent in Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to:
C:\WINDOWS\system32\cmd.exe /D /S /C start "Agent with AutoLogon" "C:\agent\runAgent.lnk"

Link Property