Load UserProfile on RunAs

This commit is contained in:
twangboy 2016-08-31 13:57:27 -06:00
parent 9910b9c6f9
commit 3721a09ea3

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