# ========================================================= # MAX Windows Toolkit - 配置远程桌面 # ========================================================= $Common = "C:\Setup\windows\lib\common.ps1" if (Test-Path $Common) { . $Common } Show-AdminWarn Write-Header "配置远程桌面" Write-Info "1. 启用远程桌面" Write-Info "2. 禁用远程桌面" Write-Info "3. 查看 RDP 状态" Write-Line $Choice = Read-Host " 请选择" switch ($Choice) { "1" { try { Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" ` -Name "fDenyTSConnections" -Value 0 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" -ErrorAction SilentlyContinue New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Force | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" ` -Name "fDenyTSConnections" -Type DWord -Value 0 powercfg /change standby-timeout-ac 0 powercfg /change hibernate-timeout-ac 0 Write-OK "远程桌面已启用" } catch { Write-Err "启用远程桌面失败" Write-Muted $_.Exception.Message } } "2" { try { Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" ` -Name "fDenyTSConnections" -Value 1 Disable-NetFirewallRule -DisplayGroup "Remote Desktop" -ErrorAction SilentlyContinue Write-OK "远程桌面已禁用" } catch { Write-Err "禁用远程桌面失败" Write-Muted $_.Exception.Message } } "3" { try { $Value = Get-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" ` -Name "fDenyTSConnections" if ($Value.fDenyTSConnections -eq 0) { Write-OK "远程桌面状态: 已启用" } else { Write-Warn "远程桌面状态: 已禁用" } Get-NetFirewallRule -DisplayGroup "Remote Desktop" -ErrorAction SilentlyContinue | Format-Table DisplayName, Enabled, Direction, Action -AutoSize } catch { Write-Err "查看 RDP 状态失败" Write-Muted $_.Exception.Message } } default { Write-Err "无效选项" } } Write-Line Write-OK "远程桌面配置完成" Pause-Max