diff --git a/Endpoints/RemoteEndpoint.cs b/Endpoints/RemoteEndpoint.cs index d01d5d5..ffd1273 100644 --- a/Endpoints/RemoteEndpoint.cs +++ b/Endpoints/RemoteEndpoint.cs @@ -31,6 +31,7 @@ public static class RemoteEndpoint // PowerShell-Script ausliefern app.MapGet("/remote.ps1", (Delegate)ServeScript); + app.MapGet("/remote", (Delegate)ServeScript); } private static async Task HandleWebSocket(HttpContext ctx, RemoteConnectionManager mgr) diff --git a/wwwroot/remote.ps1 b/wwwroot/remote.ps1 index 25325f8..bc8084d 100644 --- a/wwwroot/remote.ps1 +++ b/wwwroot/remote.ps1 @@ -51,6 +51,15 @@ try { $cts = New-Object System.Threading.CancellationTokenSource $ct = $cts.Token + # Ctrl+C abfangen → CancellationToken ausloesen + [Console]::TreatControlCAsInput = $false + $cancelHandler = [System.ConsoleCancelEventHandler]{ + param($s, $e) + $e.Cancel = $true + $cts.Cancel() + } + [Console]::add_CancelKeyPress($cancelHandler) + # TLS 1.2 erzwingen (fuer aeltere Windows-Versionen) [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 @@ -152,11 +161,16 @@ try { } } catch [System.OperationCanceledException] { # Ctrl+C +} catch [System.AggregateException] { + # Kann durch CancellationToken in .GetAwaiter().GetResult() kommen } catch [System.Net.WebSockets.WebSocketException] { Write-Host " Verbindung verloren." -ForegroundColor Red } catch { Write-Host " Fehler: $_" -ForegroundColor Red } finally { + # Event-Handler entfernen + try { [Console]::remove_CancelKeyPress($cancelHandler) } catch { } + if ($ws -and $ws.State -eq [System.Net.WebSockets.WebSocketState]::Open) { try { $closeCt = (New-Object System.Threading.CancellationTokenSource(3000)).Token