Failed to stop TeamCity build agent service via net.exe. Failed to start process. Return code was 2 not equal to zero.

teamcity

I installed TeamCity locally on my Windows 8 machine. When I open TeamCity via my browser it shows 0 agents. When I look at the agents, I see 1 agent disconnected with a message that it unregistered itself and the message "will update".

I wait but nothing happens.

I checked the log file in C:\TeamCity\buildAgent\logs\teamcity-agent.log and saw that message "Upgrade call received from the build server".

I then checked upgrade.log in the same log folder, and saw the message Failed to stop TeamCity build agent service via net.exe

I had installed the TeamCity service and build agent using a user account (aka not SYSTEM).

Best Answer

The solution turned out to be to grant permissions to manage that service to the account the services are running as. You can find a detailed walkthrough on Thom's HeadSpace blog at:

http://thommck.wordpress.com/2011/12/02/how-to-allow-non-admins-to-start-and-stop-system-services/

I'll put the summarize notes here, but you should really checkout his blog post for detailed steps and screenshots, makes it much easier.

You short of it that you create a Security Template.

  1. Start the Microsoft Management Console
  2. Add the Security Configuration and Analysis snap in
  3. Add the Security Templates snap in
  4. Add a new "New Template Search Path" (e.g. c:\SecurityTemplates)
  5. Create a "New Template"
  6. Import your .inf file
  7. Analyze Computer...
  8. Select the service in question
  9. Define this policy in the database
  10. Edit Security...
  11. Configure Computer...