# Self Hosted Agent as Service

* Open PowerShell as an administrator.
    
* Navigate to the directory where your self-hosted agent is located. You mentioned that you go to the agent folder and run `./run.cmd`, so navigate to that directory using the `cd` command.
    
* Once you are in the agent directory, you can install the agent as a Windows service using the following command:
    
    ```plaintext
    powershell
    ```
    
* ```plaintext
    .\config.cmd service install
    ```
    
* This command will install your self-hosted agent as a Windows service, and it will start automatically when the computer is restarted.
    
* To verify the service installation and ensure it's set to start automatically, you can use the following command to configure the service:
    
    ```plaintext
    powershell
    ```
    
* ```plaintext
    sc config "YourAgentServiceName" start=auto
    ```
    
    Replace `"YourAgentServiceName"` with the actual name of your agent service, which is typically the default name unless you specified a different name during the agent setup. This command sets the service to start automatically.
    
* You can now start the service manually for the current session using the `sc` command:
    
    ```plaintext
    powershell
    ```
    

1. ```plaintext
    sc start "YourAgentServiceName"
    ```
    
    Again, replace `"YourAgentServiceName"` with the actual name of your agent service.
    

Now, your self-hosted agent should be set up as a Windows service and will automatically start whenever the computer is restarted. Make sure to replace `"YourAgentServiceName"` with the actual name of your agent service, which you can verify in the Windows Services tool.
