From d32a43a3d91607be602500b36c270ae1e0ee943a Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 16 Nov 2025 15:23:00 -0500 Subject: [PATCH 1/2] Code Quality: Skip USERNAME env var when launching processes Prevents the USERNAME environment variable from being set for child processes to avoid issues where files are executed as the SYSTEM user. Addresses problem described in issue #12139. --- src/Files.App/Utils/Shell/LaunchHelper.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Files.App/Utils/Shell/LaunchHelper.cs b/src/Files.App/Utils/Shell/LaunchHelper.cs index f926df1785da..760e12e3df9c 100644 --- a/src/Files.App/Utils/Shell/LaunchHelper.cs +++ b/src/Files.App/Utils/Shell/LaunchHelper.cs @@ -100,6 +100,17 @@ private static async Task HandleApplicationLaunch(string application, stri process.StartInfo.Arguments = arguments; // Refresh env variables for the child process + foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine)) + { + string key = (string)ent.Key; + + // Skip USERNAME to avoid issues where files were executed as SYSTEM user (#12139) + if (key == "USERNAME") + continue; + + process.StartInfo.EnvironmentVariables[key] = (string)ent.Value; + } + foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User)) process.StartInfo.EnvironmentVariables[(string)ent.Key] = (string)ent.Value; From 4b102e6c0d9992edf080282ab4c31d93f6fec262 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 17 Nov 2025 16:46:41 -0500 Subject: [PATCH 2/2] Handle USERNAME env var case-insensitively in LaunchHelper --- src/Files.App/Utils/Shell/LaunchHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Utils/Shell/LaunchHelper.cs b/src/Files.App/Utils/Shell/LaunchHelper.cs index 760e12e3df9c..46f8a323da27 100644 --- a/src/Files.App/Utils/Shell/LaunchHelper.cs +++ b/src/Files.App/Utils/Shell/LaunchHelper.cs @@ -105,7 +105,7 @@ private static async Task HandleApplicationLaunch(string application, stri string key = (string)ent.Key; // Skip USERNAME to avoid issues where files were executed as SYSTEM user (#12139) - if (key == "USERNAME") + if (string.Equals(key, "USERNAME", StringComparison.OrdinalIgnoreCase)) continue; process.StartInfo.EnvironmentVariables[key] = (string)ent.Value;