How to Automatically Log On a User in Windows 10 After Remote Desktop Logoff: A Comprehensive Guide

In industrial environments where PLC (Programmable Logic Controller) systems running on Windows 10 IoT are in use, remote access is crucial for monitoring, troubleshooting, and managing system configurations. One common problem that arises when using Remote Desktop to access such devices is that logging into a remote session causes the locally logged-in user (in this case, the Administrator) to be logged out. After logging out from the remote session, the local user is left in a logged-out state, requiring manual intervention to log in again, which can be time-consuming and frustrating.

To improve productivity and streamline remote management of Windows 10 IoT-based PLCs, an automated solution is needed to log the user back in automatically when the remote session ends. This article explores different solutions to automatically log on a user in Windows 10 after logging out from a Remote Desktop session. We'll cover several methods, including registry tweaks, scripts, and group policy settings.

Table of Contents

Introduction to Automatic Logon in Windows 10

Understanding Windows Logon Behavior

Challenges with Remote Desktop and Local Logon

Solution 1: Using AutoAdminLogon in Windows Registry

Solution 2: Creating a PowerShell Script for Auto Logon

Solution 3: Batch Script Approach

Solution 4: Modifying Group Policy Settings for Auto Logon

Security Considerations

Common Issues and Troubleshooting

Conclusion

Frequently Asked Questions (FAQ)

1. Introduction to Automatic Logon in Windows 10

Automatic logon is a feature in Windows that allows a user to log into the system without entering a username or password. This is particularly useful in environments where the machine should always be available for use after a restart or when returning from a session disconnect, without requiring manual input from the user.

In the context of Windows 10 IoT-based PLCs, automatic logon can simplify remote management and prevent disruptions to the local user experience. However, configuring automatic logon after a remote desktop session is terminated requires more than just enabling the AutoAdminLogon registry key. The solution involves adjusting settings to ensure the local user automatically logs in again after a remote user logs off.

2. Understanding Windows Logon Behavior

When a user logs into a Windows machine, the system typically keeps the user logged in until they either log off manually or the system is restarted. However, in environments using Remote Desktop, logging into the machine remotely causes the local user to be logged off to allow for the remote session to take over. Once the remote session ends, the local user remains logged out until someone manually logs back in.

The challenge arises when you want the machine to automatically log in a specific user (e.g., an administrator) once the remote session ends. Without an automatic logon mechanism in place, someone would need to manually input the credentials to restore the session, which can be inconvenient and inefficient in a production environment.

3. Challenges with Remote Desktop and Local Logon

The main issue you're facing is that when you log into your PLC via Remote Desktop, the local user (Admin) is logged out. After logging out from the remote session, you want Windows to automatically log the Admin back in locally. This behavior is standard in Windows 10 but can be disruptive in a factory setting.

Here are the challenges:

Local user logoff during Remote Desktop session: Windows logs off the local user when a remote session starts, which is undesirable for continuous operation.

Automatic re-login post remote session: After the remote session ends, you want the system to automatically log back into the local Admin account.

Security Concerns: While security may not be a major issue in your environment, automated logins still present a potential risk, especially in environments that require confidentiality or compliance.

4. Solution 1: Using AutoAdminLogon in Windows Registry

The most straightforward method to achieve automatic logon is by modifying the Windows registry to enable the AutoAdminLogon feature. This method allows you to specify a user account (e.g., Admin) that will be automatically logged in after a restart.

Steps to Enable AutoAdminLogon:

Press Win + R, type regedit, and press Enter to open the registry editor.

Navigate to the following key:

Copy code

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

In the right pane, find the AutoAdminLogon entry. If it doesn’t exist, create a new String Value by right-clicking and selecting New > String Value. Name it AutoAdminLogon.

Set the value of AutoAdminLogon to 1 to enable automatic logon.

Next, create or modify the DefaultUserName and DefaultPassword values: DefaultUserName should be the username of the Admin account.

DefaultPassword should be the password for the Admin account.

Close the registry editor and restart the machine.

This will ensure that after a system restart or the machine boots up, the Admin account will log in automatically without requiring user input.

Limitations of AutoAdminLogon:

Doesn’t re-login automatically after Remote Desktop logoff: The AutoAdminLogon feature only works during startup or reboot. When a Remote Desktop session ends, the local user is still logged out, and the system will not automatically log the user back in.

Works only on first logon: It doesn’t handle automatic re-logins after remote disconnects.

5. Solution 2: Creating a PowerShell Script for Auto Logon

To achieve automatic logon after a Remote Desktop session ends, you can use a PowerShell script that triggers the login process whenever the session is logged off. The idea here is to use the script to monitor the session state and automatically log the user back in when the session ends.

PowerShell Script Example:

powershell

Copy code

$UserName = "Admin" $Password = "YourAdminPassword" # Function to perform auto logon function AutoLogon { $secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($UserName, $secpasswd) # Start the logon process Start-Process "C:\Windows\System32\runas.exe" -ArgumentList "/user:$UserName $Password" } # Detect when the session ends (logging off from RDP) while ($true) { if ((Get-WmiObject -Class Win32_ComputerSystem).UserName -eq $null) { AutoLogon Start-Sleep -Seconds 5 } Start-Sleep -Seconds 10 }

This script will continually check if the machine is logged off, and when that occurs, it will use the credentials specified to log in automatically.

Steps to Implement:

Save the script as AutoLogon.ps1.

Run the script with administrator privileges.

Schedule the script to start automatically using Task Scheduler if needed.

This solution automates the logon process after the remote session ends.

6. Solution 3: Batch Script Approach

A simpler alternative is to use a batch script that executes the control userpasswords2 command to enable automatic login. This batch file can be scheduled to run at startup.

Batch Script Example:

batch

Copy code

@echo off control userpasswords2

You can use this batch script to open the User Accounts window where you can enable automatic logon for the Admin account.

To make it run at startup, you can place the batch file in the Startup folder or configure it using Task Scheduler.

7. Solution 4: Modifying Group Policy Settings for Auto Logon

You can also configure Windows to allow automatic logon via Group Policy. However, this option is less flexible than registry-based configurations and requires additional administrative permissions.

Steps:

Open the Local Group Policy Editor by typing gpedit.msc in the Run dialog.

Navigate to the following path: sql

Copy code

Computer Configuration > Administrative Templates > System > Logon

Enable the Always wait for the network at computer startup and logon policy setting.

Set the User Group Policy loopback processing mode to Enabled.

Ensure that the AutoLogon registry entry is still configured as described above.

8. Security Considerations

While automatic logon is convenient, it does come with security risks:

Physical Access Risk: If an unauthorized person gains physical access to the machine, they could easily access the system.

Malware Risks: In a networked environment, enabling auto-login can expose the system to additional threats, as malicious actors might exploit the lack of a password prompt.

Given that the PLC in your case runs in a controlled, professional environment with trained staff, these risks might be minimal, but they should still be considered.

9. Common Issues and Troubleshooting

AutoLogon not working after a Remote Desktop session: This can happen if the system is not set to use the correct credentials, or if there’s a conflict with another user setting.

Admin account not logging in automatically: Double-check that the registry settings are configured properly and that the correct username/password is entered in the registry.

PowerShell or Batch script not running: Ensure that the script is set to execute with elevated permissions and that Task Scheduler or other automation tools are properly configured.

10. Conclusion

Setting up automatic logon for the Admin account after a Remote Desktop session is a useful feature for industrial settings where uninterrupted access to the machine is crucial. By using registry settings, PowerShell, batch scripts, or group policy configurations, you can ensure that the Admin account is automatically logged back in when a session ends.

If security is not a concern in your case, the registry method combined with a script that checks for the logoff state is likely the most straightforward solution to implement. Keep in mind that any automatic logon solution should be tested thoroughly in your environment to ensure it works as expected.

11. Frequently Asked Questions (FAQ)

Q: Can I enable automatic logon for a specific user only when logging out of Remote Desktop?

A: While Windows does not have a built-in feature to only enable auto-login after Remote Desktop logoff, you can use a combination of registry settings and scripts to achieve this functionality.

Q: Is there a way to make this setup more secure?

A: If security is a concern, you may want to consider using a more secure method for login, such as enabling two-factor authentication or using a more secure method of remote access like Windows Virtual Desktop.

Q: Can I use the same method for Windows 11 or other versions of Windows?

A: Yes, the registry settings and PowerShell scripts should work on Windows 11 as well, although some specific group policies might differ. Always test configurations on the target version of Windows.

Q: How do I stop automatic logon after I no longer need it?

A: To disable automatic logon, simply revert the registry settings or script to their previous state, or disable any Task Scheduler tasks related to the logon process.

Author's Bio: 

Rchard Mathew is a passionate writer, blogger, and editor with 36+ years of experience in writing. He can usually be found reading a book, and that book will more likely than not be non-fictional.