20-sep: [scripts] Autologon - scripts verificacion/correccion + doc actualizada

This commit is contained in:
juanminsanz
2026-09-20 22:24:10 +02:00
parent ac876f59c6
commit a0f99b897d
4 changed files with 249 additions and 14 deletions

View File

@@ -0,0 +1,69 @@
# Script para verificar la configuración actual de autologon
# NO modifica nada, solo muestra información
$winlogonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Write-Host "`n=== CONFIGURACION ACTUAL DE AUTOLOGON ===" -ForegroundColor Cyan
# Leer configuración del registro
try {
$autologon = Get-ItemProperty -Path $winlogonPath -Name "AutoAdminLogon" -ErrorAction SilentlyContinue
$username = Get-ItemProperty -Path $winlogonPath -Name "DefaultUserName" -ErrorAction SilentlyContinue
$domain = Get-ItemProperty -Path $winlogonPath -Name "DefaultDomainName" -ErrorAction SilentlyContinue
$hasPassword = Get-ItemProperty -Path $winlogonPath -Name "DefaultPassword" -ErrorAction SilentlyContinue
Write-Host "`nREGISTRO DE WINDOWS:"
Write-Host " AutoAdminLogon: $($autologon.AutoAdminLogon)" -ForegroundColor $(if ($autologon.AutoAdminLogon -eq "1") { "Green" } else { "Yellow" })
Write-Host " DefaultUserName: $($username.DefaultUserName)" -ForegroundColor $(if ($username.DefaultUserName) { "White" } else { "Red" })
Write-Host " DefaultDomainName: $($domain.DefaultDomainName)" -ForegroundColor $(if ($domain.DefaultDomainName) { "White" } else { "Red" })
Write-Host " DefaultPassword: $(if ($hasPassword.DefaultPassword) { '[CONFIGURADA]' } else { '[NO CONFIGURADA]' })" -ForegroundColor $(if ($hasPassword.DefaultPassword) { "White" } else { "Red" })
Write-Host "`nUSUARIO ACTUAL REAL:"
Write-Host " Usuario: $env:USERNAME" -ForegroundColor Cyan
Write-Host " Dominio/Workgroup: $env:USERDOMAIN" -ForegroundColor Cyan
Write-Host " Nombre del PC: $env:COMPUTERNAME" -ForegroundColor Cyan
Write-Host "`nCOMPARACION:"
# Verificar si coinciden
$usuarioConfigurado = $username.DefaultUserName
$dominioConfigurado = $domain.DefaultDomainName
if ($usuarioConfigurado -eq $env:USERNAME) {
Write-Host " ✓ Usuario coincide" -ForegroundColor Green
} else {
Write-Host " ✗ Usuario NO coincide" -ForegroundColor Red
Write-Host " Configurado: $usuarioConfigurado" -ForegroundColor Gray
Write-Host " Real: $env:USERNAME" -ForegroundColor Gray
}
if ($dominioConfigurado -eq $env:COMPUTERNAME) {
Write-Host " ✓ Dominio correcto (nombre del PC)" -ForegroundColor Green
} elseif ($dominioConfigurado -eq $env:USERDOMAIN) {
Write-Host " ~ Dominio usa USERDOMAIN" -ForegroundColor Yellow
Write-Host " Actual: $dominioConfigurado" -ForegroundColor Gray
Write-Host " Recomendado: $env:COMPUTERNAME" -ForegroundColor Gray
} else {
Write-Host " ✗ Dominio NO coincide" -ForegroundColor Red
Write-Host " Configurado: $dominioConfigurado" -ForegroundColor Gray
Write-Host " Nombre PC: $env:COMPUTERNAME" -ForegroundColor Gray
}
if ($autologon.AutoAdminLogon -eq "1" -and $username.DefaultUserName -and $hasPassword.DefaultPassword) {
Write-Host "`n[RESULTADO] Autologon ACTIVO" -ForegroundColor Green
if ($username.DefaultUserName -ne $env:USERNAME) {
Write-Host "[PROBLEMA] Usuario configurado NO es el actual → puede crear usuario nuevo" -ForegroundColor Red
Write-Host "[SOLUCION] Ejecutar: .\fix_autologon.ps1" -ForegroundColor Yellow
}
} elseif ($autologon.AutoAdminLogon -eq "1") {
Write-Host "`n[RESULTADO] Autologon ACTIVO pero INCOMPLETO (falta usuario o contraseña)" -ForegroundColor Yellow
} else {
Write-Host "`n[RESULTADO] Autologon DESACTIVADO" -ForegroundColor Gray
}
} catch {
Write-Host "[ERROR] No se pudo leer la configuración: $_" -ForegroundColor Red
}
Write-Host "`n========================================`n" -ForegroundColor Cyan

View File

@@ -0,0 +1,33 @@
# Script para DESHABILITAR autologon
# Ejecutar como ADMINISTRADOR
# Verificar que se ejecuta como Admin
$esAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $esAdmin) {
Write-Host "[ERROR] Este script debe ejecutarse como Administrador." -ForegroundColor Red
exit 1
}
Write-Host "`n=== DESACTIVAR AUTOLOGON ===" -ForegroundColor Cyan
$winlogonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
try {
# Deshabilitar autologon
Set-ItemProperty -Path $winlogonPath -Name "AutoAdminLogon" -Value "0"
# Eliminar contraseña almacenada (seguridad)
Remove-ItemProperty -Path $winlogonPath -Name "DefaultPassword" -ErrorAction SilentlyContinue
Write-Host "`n[OK] Autologon DESACTIVADO." -ForegroundColor Green
Write-Host "Al reiniciar, Windows pedirá contraseña normalmente." -ForegroundColor White
Write-Host "`nPara reactivar autologon correctamente:" -ForegroundColor Yellow
Write-Host " .\fix_autologon.ps1" -ForegroundColor White
} catch {
Write-Host "`n[ERROR] No se pudo deshabilitar autologon: $_" -ForegroundColor Red
exit 1
}
Write-Host "`n========================================`n" -ForegroundColor Cyan

77
scripts/fix_autologon.ps1 Normal file
View File

@@ -0,0 +1,77 @@
# Script para CORREGIR autologon y que use el usuario ACTUAL
# Ejecutar como ADMINISTRADOR
param(
[Parameter(Mandatory=$false, HelpMessage="Contraseña/PIN de Windows (si no se proporciona, se pide de forma segura)")]
[string]$Password
)
# Verificar que se ejecuta como Admin
$esAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $esAdmin) {
Write-Host "[ERROR] Este script debe ejecutarse como Administrador." -ForegroundColor Red
Write-Host "Click derecho → 'Ejecutar como administrador'" -ForegroundColor Yellow
exit 1
}
Write-Host "`n=== CONFIGURACION DE AUTOLOGON CORRECTO ===" -ForegroundColor Cyan
# Detectar usuario actual REAL
$username = $env:USERNAME
$computername = $env:COMPUTERNAME
Write-Host "`nUsuario detectado: $computername\$username" -ForegroundColor White
# Pedir contraseña si no se pasó como parámetro
if (-not $Password) {
Write-Host "`nIntroduce tu contraseña/PIN de Windows:" -ForegroundColor Yellow
$securePassword = Read-Host -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePassword)
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
}
# Mostrar lo que se va a configurar (SIN mostrar la contraseña)
Write-Host "`nSe configurará autologon con:" -ForegroundColor Cyan
Write-Host " AutoAdminLogon: 1" -ForegroundColor White
Write-Host " DefaultUserName: $username" -ForegroundColor White
Write-Host " DefaultDomainName: $computername" -ForegroundColor White
Write-Host " DefaultPassword: [OCULTA]" -ForegroundColor White
Write-Host "`n¿Continuar? (S/N): " -ForegroundColor Yellow -NoNewline
$respuesta = Read-Host
if ($respuesta -ne "S" -and $respuesta -ne "s") {
Write-Host "[CANCELADO] No se realizaron cambios." -ForegroundColor Gray
exit 0
}
# Aplicar configuración
$winlogonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
try {
Set-ItemProperty -Path $winlogonPath -Name "AutoAdminLogon" -Value "1"
Set-ItemProperty -Path $winlogonPath -Name "DefaultUserName" -Value $username
Set-ItemProperty -Path $winlogonPath -Name "DefaultPassword" -Value $Password
Set-ItemProperty -Path $winlogonPath -Name "DefaultDomainName" -Value $computername # CLAVE: nombre del PC, no USERDOMAIN
Write-Host "`n[OK] Autologon configurado correctamente." -ForegroundColor Green
Write-Host "`nAl reiniciar el PC, Windows entrará automáticamente como:" -ForegroundColor Cyan
Write-Host " $computername\$username" -ForegroundColor White
Write-Host "`nPrueba:" -ForegroundColor Yellow
Write-Host " 1. Reinicia el PC" -ForegroundColor White
Write-Host " 2. Verifica que entra sin pedir contraseña" -ForegroundColor White
Write-Host " 3. Si funciona, prueba encendido remoto desde Telegram" -ForegroundColor White
Write-Host "`nPara verificar la configuración:" -ForegroundColor Yellow
Write-Host " .\check_autologon_status.ps1" -ForegroundColor White
Write-Host "`nPara desactivar autologon:" -ForegroundColor Yellow
Write-Host " .\disable_autologon.ps1" -ForegroundColor White
} catch {
Write-Host "`n[ERROR] No se pudo configurar autologon: $_" -ForegroundColor Red
exit 1
}
Write-Host "`n========================================`n" -ForegroundColor Cyan