mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Load UserProfile on RunAs
This commit is contained in:
parent
9910b9c6f9
commit
3721a09ea3
@ -292,13 +292,16 @@ def runas_system(cmd, username, password):
|
|||||||
if '\\' in username:
|
if '\\' in username:
|
||||||
domain, username = username.split('\\')
|
domain, username = username.split('\\')
|
||||||
|
|
||||||
# Get User Token
|
# Load User and Get Token
|
||||||
token = win32security.LogonUser(username,
|
token = win32security.LogonUser(username,
|
||||||
domain,
|
domain,
|
||||||
password,
|
password,
|
||||||
win32con.LOGON32_LOGON_INTERACTIVE,
|
win32con.LOGON32_LOGON_INTERACTIVE,
|
||||||
win32con.LOGON32_PROVIDER_DEFAULT)
|
win32con.LOGON32_PROVIDER_DEFAULT)
|
||||||
|
|
||||||
|
# Load the User Profile
|
||||||
|
handle_reg = win32profile.LoadUserProfile(token, {'UserName': username})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get Unrestricted Token (UAC) if this is an Admin Account
|
# Get Unrestricted Token (UAC) if this is an Admin Account
|
||||||
elevated_token = win32security.GetTokenInformation(
|
elevated_token = win32security.GetTokenInformation(
|
||||||
@ -395,6 +398,9 @@ def runas_system(cmd, username, password):
|
|||||||
# Close handle to process
|
# Close handle to process
|
||||||
win32api.CloseHandle(hProcess)
|
win32api.CloseHandle(hProcess)
|
||||||
|
|
||||||
|
# Unload the User Profile
|
||||||
|
win32profile.UnloadUserProfile(token, handle_reg)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user