# ============================================ # Setup AutoLogon Windows # À exécuter en tant qu'Administrateur # ============================================ # Vérifier les droits admin if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "❌ Ce script doit être exécuté en tant qu'Administrateur." -ForegroundColor Red exit 1 } $regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" $currentUser = $env:USERNAME $machineName = $env:COMPUTERNAME # Vérifier si AutoLogon est déjà configuré $existingUser = (Get-ItemProperty -Path $regPath -Name "DefaultUserName" -ErrorAction SilentlyContinue).DefaultUserName if ($existingUser) { Write-Host "" Write-Host "⚠️ AutoLogon déjà configuré pour l'utilisateur : $existingUser" -ForegroundColor Yellow $confirm = Read-Host "Voulez-vous reconfigurer? (O/N)" if ($confirm -notmatch "^[Oo]$") { Write-Host "Annulé." -ForegroundColor Cyan exit 0 } } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host " Configuration AutoLogon Windows" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "Utilisateur détecté : $currentUser" -ForegroundColor Cyan Write-Host "" # Demander le mot de passe en clair $password = Read-Host "Mot de passe de $currentUser" if ([string]::IsNullOrWhiteSpace($password)) { Write-Host "❌ Le mot de passe ne peut pas être vide." -ForegroundColor Red exit 1 } # Valider le mot de passe contre le compte local Add-Type -AssemblyName System.DirectoryServices.AccountManagement try { $ctx = New-Object System.DirectoryServices.AccountManagement.PrincipalContext( [System.DirectoryServices.AccountManagement.ContextType]::Machine, $machineName) $valid = $ctx.ValidateCredentials($currentUser, $password) } catch { Write-Host "⚠️ Impossible de valider le mot de passe : $_" -ForegroundColor Yellow $valid = $false } if (-not $valid) { Write-Host "" Write-Host "❌ Mot de passe incorrect pour $currentUser." -ForegroundColor Red exit 1 } Write-Host "✅ Mot de passe validé." -ForegroundColor Green Write-Host "" Write-Host "Configuration en cours..." -ForegroundColor Cyan # Appliquer les clés de registre Set-ItemProperty -Path $regPath -Name "AutoAdminLogon" -Value "1" -Type String Set-ItemProperty -Path $regPath -Name "DefaultDomainName" -Value $machineName -Type String Set-ItemProperty -Path $regPath -Name "DefaultUserName" -Value $currentUser -Type String Set-ItemProperty -Path $regPath -Name "DefaultPassword" -Value $password -Type String Set-ItemProperty -Path $regPath -Name "ForceAutoLogon" -Value "1" -Type String # Nettoyer le mot de passe de la mémoire $password = $null [System.GC]::Collect() Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host "✅ AutoLogon configuré avec succès !" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host " Utilisateur : $currentUser" -ForegroundColor White Write-Host " AutoLogon : Activé" -ForegroundColor White Write-Host "" Write-Host "⚠️ Le mot de passe est stocké en clair dans le registre." -ForegroundColor Yellow Write-Host " Assurez-vous que l'accès physique à ce poste est sécurisé." -ForegroundColor Yellow Write-Host "" $reboot = Read-Host "Redémarrer maintenant pour appliquer? (O/N)" if ($reboot -match "^[Oo]$") { Write-Host "Redémarrage dans 5 secondes..." -ForegroundColor Yellow Start-Sleep -Seconds 5 Restart-Computer -Force }