Merge pull request #35952 from twangboy/fix_win_runas_2016.3

Load UserProfile when using RunAs (2016.3)
This commit is contained in:
Mike Place 2016-09-02 00:18:15 +09:00 committed by GitHub
commit f7b85cb70b

View file

@ -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