From 8c8792d81bdd61c318b7c41bb7d1f6db0f7a81f0 Mon Sep 17 00:00:00 2001 From: twangboy Date: Fri, 20 Sep 2024 10:57:48 -0600 Subject: [PATCH] Use cmd /c with runas on Windows to allow compound commands --- salt/utils/win_runas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/utils/win_runas.py b/salt/utils/win_runas.py index aa2df51dbfc..c9efa865117 100644 --- a/salt/utils/win_runas.py +++ b/salt/utils/win_runas.py @@ -209,7 +209,7 @@ def runas(cmdLine, username, password=None, cwd=None): int(user_token), logonflags=1, applicationname=None, - commandline=cmdLine, + commandline=f'cmd /c "{cmdLine}"', currentdirectory=cwd, creationflags=creationflags, startupinfo=startup_info, @@ -310,7 +310,7 @@ def runas_unpriv(cmd, username, password, cwd=None): domain=domain, password=password, logonflags=salt.platform.win.LOGON_WITH_PROFILE, - commandline=cmd, + commandline=f'cmd /c "{cmd}"', startupinfo=startup_info, currentdirectory=cwd, )