Skip to content

Commit 62bf9ac

Browse files
authored
Code Quality: Skip USERNAME env var when launching processes (#17872)
1 parent 80a5f59 commit 62bf9ac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Files.App/Utils/Shell/LaunchHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ private static async Task<bool> HandleApplicationLaunch(string application, stri
100100
process.StartInfo.Arguments = arguments;
101101

102102
// Refresh env variables for the child process
103+
foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine))
104+
{
105+
string key = (string)ent.Key;
106+
107+
// Skip USERNAME to avoid issues where files were executed as SYSTEM user (#12139)
108+
if (string.Equals(key, "USERNAME", StringComparison.OrdinalIgnoreCase))
109+
continue;
110+
111+
process.StartInfo.EnvironmentVariables[key] = (string)ent.Value;
112+
}
113+
103114
foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User))
104115
process.StartInfo.EnvironmentVariables[(string)ent.Key] = (string)ent.Value;
105116

0 commit comments

Comments
 (0)