# Auto Logon

## PowerShell Script

AutoLogon can be configured to either automatically log in once after a reboot or permanently.

The following script is the [Single AutoLogon](/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/auto-logon.md#single-autologon) sample PowerShell script, alternatively use the [Permanent AutoLogon ](/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/auto-logon.md#permenant-autologon)sample PowerShell script. Copy it and save it as a **.ps1** file. For further information on hosting this script see [Quick Guide to Self-Hosting Custom Scripts](/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/quick-guide-to-self-hosting-custom-scripts.md). &#x20;

### Single AutoLogon

This script enables AutoLogon **only once** **after a restart**. After the second restart, the user will be prompted to log in.

```javascript
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$DefaultUsername = $args[0]
$DefaultPassword =  $args[1] 
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String 
Set-ItemProperty $RegPath "DefaultUsername" -Value "$DefaultUsername" -type String 
Set-ItemProperty $RegPath "DefaultPassword" -Value "$DefaultPassword" -type String
Set-ItemProperty $RegPath "AutoLogonCount" -Value "1" -type DWord
Start-Sleep -Seconds 5 ; Restart-Computer -Force. 
```

### Permanent AutoLogon

This script enables AutoLogon **permanently**; no matter how many times the computer is restarted, it will always automatically log in.&#x20;

```javascript
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$DefaultUsername = $args[0]
$DefaultPassword =  $args[1] 
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String 
Set-ItemProperty $RegPath "DefaultUsername" -Value "$DefaultUsername" -type String 
Set-ItemProperty $RegPath "DefaultPassword" -Value "$DefaultPassword" -type String
Start-Sleep -Seconds 5 ; Restart-Computer -Force
```

## Custom Script Settings

The table below outlines all the fields that need to be set when creating this custom script.&#x20;

{% hint style="info" %}
For a detailed guide, refer to [Create an AutoLogon Custom Script](/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/auto-logon.md#create-an-autologon-custom-script).
{% endhint %}

| Field        | Value                                                                                                                                                                                                                                                                                 |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name         | **Single AutoLogon**                                                                                                                                                                                                                                                                  |
| URL          | <p><a href="http://www.faronics.org/proservices/SingleAutoLogon.ps1"><http://www.faronics.org/proservices/SingleAutoLogon.ps1></a> OR</p><p><a href="http://www.faronics.org/proservices/PermanentAutoLogon.ps1"><http://www.faronics.org/proservices/PermanentAutoLogon.ps1></a></p> |
| Type         | **PowerShell**                                                                                                                                                                                                                                                                        |
| Command-Line | **yourusername yourpassword**                                                                                                                                                                                                                                                         |
| Run As       | **System Account** or **Specified User Account**                                                                                                                                                                                                                                      |

{% hint style="info" %}
Note: This forces the workstation to restart and log in with the specified AutoLogon account.

The admin needs to specify the username and password in the command line section using the format USERNAME PASSWORD (just a blank space between the username and password, no quotes needed).
{% endhint %}

## Create an AutoLogon Custom Script

![Create a Custom Script](/files/-MVTMQo7yXAzeNjC65UE)

1\. Select the **Control Grid** tab on the top menu bar.

2\. Navigate to the **Applications** tab.

3\. Click **CUSTOM** **SCRIPT**.

4\. Select **Create** **Custom** **Script**.

5\. Enter a **Name** for the script, **Single** **AutoLogon**, in this example. Use any name you'd like to use.

![Creating a Custom Script for Single AutoLogon](/files/-M_X2FFP-EIFeQk2Sncc)

6\. Enter the **URL** that points to the location where the script is being hosted,  <http://www.faronics.org/proservices/SingleAutoLogon.ps1> in this example. You might need to download this file and host it on a link that is whitelisted in your firewall.

{% hint style="info" %}
Best Practice is to download the sample script and self-host it. You can do this for free with GitHub. See the [Quick Guide to Self-Hosting Custom Scripts](/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/quick-guide-to-self-hosting-custom-scripts.md) for more information.
{% endhint %}

7\. Select the script type: **Powershell**.

8\. **Command Line**: Enter the **username** followed by the **password** (separated only by a space) for the user account to automatically log into the computer.

9\. Select the account to **Run As**; either **System Accoun**t or **Specified User Account**.

10\. Click **SAVE TO GRID**.

{% hint style="info" %}
Once saved, the script can be pushed to an individual computer or groups of computers. It can also be scheduled using a Policy.

For a guide on how to run your Custom Script, see [Pushing the Script](/faronicsdeploy/custom-scripts-powershell-vb-batch.md#pushing-the-script).
{% endhint %}

{% hint style="success" %}
The script will now appear in the list of Custom Scripts. It will also be available to select from the Applications Control Grid View.&#x20;

Search for the script in the grid using the search option. If your applications are grouped, you will see a column named **Custom** **Scripts**. Selecting the **Custom Script header** will display all the scripts that have been added to the grid.&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.faronics.com/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/auto-logon.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
