Auto start build agent in interactive mode

Problem:

I need my build agent to auto login and start in interactive mode.

Solution:

Enable Windows auto login and add a shortcut to the startup folder.

Explanation:

I run Coded UI and Selenium UI test using my build agent. To do so the agent must be run in interactive mode. However, if you configure your agent to run interactive, it will not restart automatically after a reboot. If your system is configured to automatically install updates, your server may get rebooted without you knowing and prevent your agent from starting.

To solve this you can configure Windows to automatically log in a user and start the agent in interactive mode for you. To begin we need to enable automatic log in.

  1. Press Windows Key + R to open the Run dialog
  2. Type in the following and press enter:
    control userpasswords2
  3. Uncheck the box for User must enter a user name and password to use this computer.
  4. Click the Apply button
    You will be prompted by an Automatically sign in dialog
  5. Enter the password for the user
  6. Click OK
  7. Click OK on the Users Accounts dialog

Now every time your machine is rebooted the configured user will automatically login to the machine.

Now we need to make sure that once the user is logged in that our agent starts in interactive mode. To do this we are going to create a shortcut that will start our agent then simply place that shortcut in the startup folder for Windows.

  1. Right-click the desktop
  2. Select New / Shortcut
  3. Enter cmd
  4. Click Next
  5. Change the name to Start Agent
  6. Click Finish
  7. Right-click on the new shortcut
  8. Select Properties
  9. Append /c {pathToVsoagent.exe} to the target
    If you installed your agent to C:\Agent, your target should look like this: C:\Windows\System32\cmd.exe /c c:\agent\agent\vsoagent.exe
  10. Click OK

If you double click the shortcut, your agent will start in interactive mode. Now we need to copy this shortcut into the startup folder for Windows. This will ensure that each time we login the agent is started.

  1. Press Windows Key + R to open the Run dialog
  2. Type in the following
    shell:startup
  3. Click OK
    This will open the Startup folder in Windows Explorer.
  4. Drag and drop the shortcut to this folder

Now whenever your machine is restarted your agents will start up in interactive mode.

Comments (7) -

  • Robb Schiefer

    9/9/2015 8:17:32 PM | Reply

    Thanks for writing this post!  We have an issue at work however which prevents us from using this method.  Our corporate group policy settings do not allow us to turn off the "user must login" checkbox.  I had expected the 2015 Windows Service agent to run in interactive mode.  Is that not possible?

    • Donovan

      10/7/2015 2:27:20 PM | Reply

      I tried getting the service to interact with the desktop but it did not work. I will play around with it some more.

  • Derek Keeler

    9/10/2015 5:38:17 AM | Reply

    Thanks for the tip on this one Donovan.

    Interactive mode is required for Windows 10 Store Applications (UWP applications):

    - Running unit tests in containers
    - Coded UI tests / XAML UI automation
    - Windows Application Certification Kit (WACK) automation

  • Teofil

    6/25/2018 8:24:18 AM | Reply

    Hi.
    With latest agent versions, this setup is done by the agent configuration.
    Do you know how exactly it is implemented? Because I cannot find any shortcut in the Windows startup folder.

    Thanks.

    • Donovan

      6/27/2018 2:40:46 PM | Reply

      I do not I am afraid.

  • Subhash

    9/27/2018 3:09:33 PM | Reply

    Hi,
    Good article, we have still one issue , that is we configured the VSTS agent in Interactive mode to run the Automated UI tests, we are able to succeed with this , now our blocker is we were not able to set this interactive agent in running state always,whenever we are disconnecting from the agent machine our agent is going offline. could you please help us in fixing this,

Add comment

Loading