Why am I getting a permission error for AgentService.exe after Azure agent installation from Agent Pool?

Chris 0 Reputation points
2025-02-28T01:48:50.0066667+00:00

I've currently trying to install an agent from Azure Devops > Project Settings > Agent Pools > Agents. I've set up the machines, and am able to get the agent itself onto the machine, and run them manually. However, I cannot run them as a service because during the installation, I get the following error:

An error occurred trying to start process '"C:\agent\bin\AgentService.exe"' with working directory 'C:\azagent'. Access is denied.

I would really appreciate any help resolving this error.

I have tried several credentials, admin, non-admin, new users, etc. but for some reason, I cannot seem to get past this error. Is there a particular user I'm supposed to use from Azure? Is it an issue with the security settings on my computer? I've even tried testing giving the current user full access to that specific file through the property settings. None of these work. I'm wondering what I did wrong.

I can still run the agent manually via the .\run.cmd command in Powershell, but I cannot start the AgentService.exe in C:\agent\bin\AgentService.exe.

EDIT (Some more details):

PS C:\agent> .\config.cmd
  ___                      ______ _            _ _
 / _ \                     | ___ (_)          | (_)
/ /_\ \_____   _ _ __ ___  | |_/ /_ _ __   ___| |_ _ __   ___  ___
|  _  |_  / | | | '__/ _ \ |  __/| | '_ \ / _ \ | | '_ \ / _ \/ __|
| | | |/ /| |_| | | |  __/ | |   | | |_) |  __/ | | | | |  __/\__ \
\_| |_/___|\__,_|_|  \___| \_|   |_| .__/ \___|_|_|_| |_|\___||___/
                                   | |
        agent v4.251.0             |_|          (commit 69c6517)
>> Connect:
Enter server URL > https://xxx.visualstudio.com
Enter authentication type (press enter for PAT) >
Enter personal access token > ***
Connecting to server ...
>> Register Agent:
Enter agent pool (press enter for default) > TEST-QA1
Enter agent name (press enter for SRVR1) >
Scanning for tool capabilities.
Connecting to the server.
Pool TEST-QA1 already contains an agent with name SRVR1.
Enter replace? (Y/N) (press enter for N) > Y
Successfully replaced the agent
Testing agent connection.
Enter work folder (press enter for _work) >
2025-02-27 21:32:31Z: Settings Saved.
Enter run agent as service? (Y/N) (press enter for N) > y
Enter enable SERVICE_SID_TYPE_UNRESTRICTED for agent service (Y/N) (press enter for N) >
Enter User account to use for the service (press enter for NT AUTHORITY\NETWORK SERVICE) > ******@abc.com
Enter Password for the account SRVR1\******@abc.com > ***
Error reported in diagnostic logs. Please examine the log for more details.
    - C:\agent\_diag\Agent_00000000-000000-utc.log
Granting file permissions to 'SRVR1\******@abc.com'.
An error occurred trying to start process '"C:\agent\bin\AgentService.exe"' with working directory 'C:\agent'. Access is denied.
PS C:\agent>
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,491 questions
Azure DevOps
{count} votes

1 answer

Sort by: Most helpful
  1. Arko 335 Reputation points Microsoft External Staff
    2025-03-05T09:16:02.9266667+00:00

    Hello Chris, In order to install an Azure DevOps Self-Hosted Agent on a windows virtual machine and configure it to run as a service.
    Go to Azure DevOps > Select your Organization.
    Navigate to Project Settings > Agent Pools.
    Click Add Pool > Give it a name (in this case I am using TEST-POOL).
    Select Self-hosted and create.

    enter image description here

    Download and extract the Agent under C:\agent

    enter image description here

    Configure the Agent under cd C:\agent and then run .\config.cmd

    Enter server URL: https://dev.azure.com/Whatever is your ORG NAME
    Enter authentication type: Just press Enter first time (default is PAT).
    Enter agent pool: Use the pool you created (For example TEST-POOL).
    Enter agent name: Any name of your choice (e.g., LAPTOP-AGENT).
    Enter work folder: Press Enter to use work.
    Enter run agent as a service?: Type y and press Enter.
    Enter user account to use for the service: Use NT AUTHORITY\NETWORK SERVICE or a custom user.

    enter image description here

    The agent should register successfully.

    Now coming to your blocker when trying the above steps i.e when you are trying to install the agent on your system and following the prompts upto where it asks to enter user account to use for the service, you are getting Access is denied error correct?

    If so, could you kindly check few things for me and let me know-

    We can start by checking if the user i.e. you have sufficient permission. For this you can goto run and type secpol.msc which should open Local Security Policy tab.

    enter image description here

    As highlighted in screenshot, Goto Security Settings > Local Policies > User Rights Assignment > Log on as a service.

    Open it and add your specified (SRVR1\user).

    Before that once check Deny log on as a service as well. If your user is listed, remove it.

    enter image description here

    Once the above checks are done, goto the path where your agent is, goto it's property section > security tab and add your user if missing or edit and cross the permission. preferably give full control.

    enter image description here

    and restart your system.

    If your issue persists, check event logs under event viewer and look for error messages related to AgentService.exe and you confirmed those details in comment section. I have replied below your comment on the meaning of those errors and how can you clear them up.

    checkout- https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/windows-agent?view=azure-devops#confirm-the-user-has-permission

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.