From 61b1c2c948cdecd315ef47fd01afaf8e167be10c Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Tue, 10 Mar 2026 14:54:20 +0100 Subject: [PATCH] fix summary cleanup - wrong CWD caused open handle and no cleanup --- src/Agent/AutopilotMonitor.Agent/buildcounter.txt | 2 +- src/Agent/AutopilotMonitor.SummaryDialog/App.xaml.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt index 816d01be..1bb7ac53 100644 --- a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt +++ b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt @@ -1 +1 @@ -420 +421 diff --git a/src/Agent/AutopilotMonitor.SummaryDialog/App.xaml.cs b/src/Agent/AutopilotMonitor.SummaryDialog/App.xaml.cs index 35a14aef..b6259e7f 100644 --- a/src/Agent/AutopilotMonitor.SummaryDialog/App.xaml.cs +++ b/src/Agent/AutopilotMonitor.SummaryDialog/App.xaml.cs @@ -189,12 +189,19 @@ namespace AutopilotMonitor.SummaryDialog Log($"SelfCleanup: spawning PowerShell to delete '{exeDir}' after PID {pid} exits"); + // WorkingDirectory MUST NOT be exeDir — on Windows a process cannot + // delete a directory that is its own CWD. When the agent launches + // the dialog via CreateProcessAsUser it sets CWD = exeDir, and + // PowerShell would inherit that, making Remove-Item silently fail. + var safeDir = Environment.GetFolderPath(Environment.SpecialFolder.System); + Process.Start(new ProcessStartInfo { FileName = psExe, Arguments = $"-NoProfile -NonInteractive -WindowStyle Hidden -EncodedCommand {encoded}", UseShellExecute = true, - WindowStyle = ProcessWindowStyle.Hidden + WindowStyle = ProcessWindowStyle.Hidden, + WorkingDirectory = safeDir }); Log("SelfCleanup: cleanup process started");