Fix RDP never being enabled
The discoverability-flyout tweak used New-Item -Force on a protected HKLM key, which throws UnauthorizedAccessException. With ErrorActionPreference Stop that aborted the bootstrap before the RDP block, so TermService stayed stopped, fDenyTSConnections stayed 1 and no RDP firewall rule was enabled. Anyone trying 3389 got a closed port. Use New-ItemProperty in a try/catch, and make the RDP block defensive (start the service, enable the rule group, log failures).
This commit is contained in:
@@ -31,10 +31,15 @@ if (-not $nic) {
|
|||||||
Set-DnsClientServerAddress -InterfaceIndex $nic.ifIndex -ServerAddresses $Config.DNS
|
Set-DnsClientServerAddress -InterfaceIndex $nic.ifIndex -ServerAddresses $Config.DNS
|
||||||
Set-NetConnectionProfile -InterfaceIndex $nic.ifIndex -NetworkCategory Private -ErrorAction SilentlyContinue
|
Set-NetConnectionProfile -InterfaceIndex $nic.ifIndex -NetworkCategory Private -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# The IP change re-triggers the "make this PC discoverable" flyout.
|
# Cosmetic: silence the "make this PC discoverable" flyout that the IP
|
||||||
New-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network' -Force | Out-Null
|
# change re-triggers. New-Item -Force throws on this protected key, and a
|
||||||
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network' `
|
# Stop preference would abort the whole bootstrap — so it must not throw.
|
||||||
-Name NewNetworkWindowOff -Value 1 -Type DWord
|
try {
|
||||||
|
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network' `
|
||||||
|
-Name NewNetworkWindowOff -Value 1 -PropertyType DWord -Force -ErrorAction Stop | Out-Null
|
||||||
|
} catch {
|
||||||
|
Write-Host "bootstrap: flyout tweak skipped ($($_.Exception.Message))"
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "bootstrap: $($nic.Name) -> $($Config.IP)/$($Config.Prefix)"
|
Write-Host "bootstrap: $($nic.Name) -> $($Config.IP)/$($Config.Prefix)"
|
||||||
}
|
}
|
||||||
@@ -55,10 +60,18 @@ if (-not (Get-NetFirewallRule -DisplayName 'Norbourg ICMPv4' -ErrorAction Silent
|
|||||||
-Direction Inbound -Action Allow -Profile Any | Out-Null
|
-Direction Inbound -Action Allow -Profile Any | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# RDP: useful for the instructor when a step misbehaves.
|
# RDP: useful for the instructor when a step misbehaves. This only opens the
|
||||||
Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' `
|
# listener; who may log on is still governed by Remote Desktop Users.
|
||||||
-Name fDenyTSConnections -Value 0
|
try {
|
||||||
Enable-NetFirewallRule -DisplayGroup 'Remote Desktop' -ErrorAction SilentlyContinue
|
Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' `
|
||||||
|
-Name fDenyTSConnections -Value 0 -ErrorAction Stop
|
||||||
|
Set-Service -Name TermService -StartupType Automatic -ErrorAction SilentlyContinue
|
||||||
|
Start-Service -Name TermService -ErrorAction SilentlyContinue
|
||||||
|
Enable-NetFirewallRule -DisplayGroup 'Remote Desktop' -ErrorAction SilentlyContinue
|
||||||
|
Write-Host 'bootstrap: RDP enabled'
|
||||||
|
} catch {
|
||||||
|
Write-Host "bootstrap: RDP setup failed ($($_.Exception.Message))"
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------ marker
|
# ------------------------------------------------------------------ marker
|
||||||
"$env:COMPUTERNAME|$($Config.Role)|$($Config.IP)|$((Get-Date).ToString('s'))" |
|
"$env:COMPUTERNAME|$($Config.Role)|$($Config.IP)|$((Get-Date).ToString('s'))" |
|
||||||
|
|||||||
Reference in New Issue
Block a user