From 3721a09ea37b3ff7023af001967d38b31385a3d3 Mon Sep 17 00:00:00 2001 From: twangboy Date: Wed, 31 Aug 2016 13:57:27 -0600 Subject: [PATCH] Load UserProfile on RunAs --- salt/utils/win_runas.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/salt/utils/win_runas.py b/salt/utils/win_runas.py index 9c7866c4a5..ced3dbcc95 100644 --- a/salt/utils/win_runas.py +++ b/salt/utils/win_runas.py @@ -292,13 +292,16 @@ def runas_system(cmd, username, password): if '\\' in username: domain, username = username.split('\\') - # Get User Token + # Load User and Get Token token = win32security.LogonUser(username, domain, password, win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT) + # Load the User Profile + handle_reg = win32profile.LoadUserProfile(token, {'UserName': username}) + try: # Get Unrestricted Token (UAC) if this is an Admin Account elevated_token = win32security.GetTokenInformation( @@ -395,6 +398,9 @@ def runas_system(cmd, username, password): # Close handle to process win32api.CloseHandle(hProcess) + # Unload the User Profile + win32profile.UnloadUserProfile(token, handle_reg) + return ret