0

So I'm having an issue with a script that enables autologon domain users. For some reason I have to run it twice for the option to be enabled on the computer.

The Script:

@echo off
REM Set variables
set /p user-name= What is the username?
set /p domain= What is the domain name?
set /p password= What is the password?

REM Enable Auto Logon
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1

REM Set Username for logon
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %user-name%

REM Set Domain
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %domain%

REM Set Password
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d %password%

I tried to use this program from the Technet and I had the same issue with it too.

I would really appreciate your help!

2 Answers2

0

If the key already exist, you need to use -Force in order to overwrite it. You can add it at the end

    $TheUser = Read-Host "What is the username?"
    $ThePassword = Read-Host "What is the password?" -AsSecureString
    $TheDomain = Read-Host "What is the domain?"
    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1 -Force
    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "$TheUser" -Force
    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value $ThePassword -Force
    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefautDomainName -value $TheDomain -Force
0

I switched to PowerShell using this script:

$TheUser = Read-Host "What is the username?"
$ThePassword = Read-Host "What is the password?" -AsSecureString
$TheDomain = Read-Host "What is the domain?"
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "$TheUser"
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value $ThePassword
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefautDomainName -value $TheDomain

But each time I execute the script I get this error message:

New-ItemProperty : The property already exists At C:\Users\Administrator\Desktop\Autologon.ps1:4 char:17 + New-ItemProperty <<<< -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1 + CategoryInfo : ResourceExists: (HKEY_LOCAL_MACH...ersion\Winlogon:String) [New-ItemProperty], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand New-ItemProperty : The property already exists At C:\Users\Administrator\Desktop\Autologon.ps1:5 char:17 + New-ItemProperty <<<< -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "$TheUser" + CategoryInfo : ResourceExists: (HKEY_LOCAL_MACH...ersion\Winlogon:String) [New-ItemProperty], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand New-ItemProperty : The property already exists At C:\Users\Administrator\Desktop\Autologon.ps1:6 char:17 + New-ItemProperty <<<< -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value $ThePassword + CategoryInfo : ResourceExists: (HKEY_LOCAL_MACH...ersion\Winlog on:String) [New-ItemProperty], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand New-ItemProperty : The property already exists At C:\Users\Administrator\Desktop\Autologon.ps1:7 char:17 + New-ItemProperty <<<< -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefautDomainName -value $TheDomain + CategoryInfo : ResourceExists: (HKEY_LOCAL_MACH...ersion\Winlogon:String) [New-ItemProperty], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand

Not sure how I can fix this and I'd really appreciate your help.