$ErrorActionPreference='Stop'; $p='HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'; if(!(Test-Path $p)){New-Item -Path $p -Force|Out-Null}; New-ItemProperty -Path $p -Name PortNumber -PropertyType DWord -Value 3389 -Force|Out-Null; New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -PropertyType DWord -Value 0 -Force|Out-Null; if(!(Get-NetFirewallRule -Name 'RDP-Repair-TCP-3389' -ErrorAction SilentlyContinue)){New-NetFirewallRule -Name 'RDP-Repair-TCP-3389' -DisplayName 'RDP Repair TCP 3389' -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow -Profile Any|Out-Null}else{Enable-NetFirewallRule -Name 'RDP-Repair-TCP-3389'}; if(!(Get-NetFirewallRule -Name 'RDP-Repair-UDP-3389' -ErrorAction SilentlyContinue)){New-NetFirewallRule -Name 'RDP-Repair-UDP-3389' -DisplayName 'RDP Repair UDP 3389' -Direction Inbound -Protocol UDP -LocalPort 3389 -Action Allow -Profile Any|Out-Null}else{Enable-NetFirewallRule -Name 'RDP-Repair-UDP-3389'}; Set-Service TermService -StartupType Manual; if((Get-Service TermService).Status -eq 'Running'){Restart-Service TermService -Force}else{Start-Service TermService}; Start-Sleep 3; Write-Host "`n=== RDP CHECK ===" -ForegroundColor Cyan; Write-Host "PortNumber:" (Get-ItemPropertyValue $p PortNumber); Write-Host "RDP enabled:" ((Get-ItemPropertyValue 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' fDenyTSConnections) -eq 0); Get-Service TermService | Format-Table Status,Name; $l=Get-NetTCPConnection -State Listen -LocalPort 3389 -ErrorAction SilentlyContinue; if($l){Write-Host 'OK: TCP 3389 IS LISTENING' -ForegroundColor Green; $l|Format-Table LocalAddress,LocalPort,OwningProcess}else{Write-Host 'ERROR: TCP 3389 IS NOT LISTENING' -ForegroundColor Red}