O script para ativar o logon automático para usuários em um domínio não funcionará, a menos que eu o execute duas vezes

0

Estou tendo um problema com um script que habilita usuários do domínio autologon. Por algum motivo, tenho que executá-lo duas vezes para que a opção seja ativada no computador.

O 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%

Eu tentei usar este programa do Technet e tive o mesmo problema com ele também.

Eu realmente aprecio sua ajuda!

    
por Youssef Karami 30.06.2015 / 23:04

2 respostas

0

Eu mudei para o PowerShell usando este 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

Mas toda vez que executo o script, recebo esta mensagem de erro:

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

Não sei como posso consertar isso e agradeço sua ajuda.

    
por 02.07.2015 / 19:25
0

Se a chave já existir, você precisará usar -Force para sobrescrevê-la. Você pode adicioná-lo no final

    $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
    
por 16.11.2017 / 09:31