Merge pull request #38325 from rallytime/bp-38247

Back-port #38247 to 2016.11
This commit is contained in:
Mike Place 2016-12-18 05:28:40 -07:00 committed by GitHub
commit 83523d2f73

View file

@ -142,9 +142,14 @@ def get_current_user():
'''
try:
user_name = win32api.GetUserNameEx(win32api.NameSamCompatible)
if user_name[-1] == '$' and win32api.GetUserName() == 'SYSTEM':
if user_name[-1] == '$':
# Make the system account easier to identify.
user_name = 'SYSTEM'
# Fetch sid so as to handle other language than english
test_user = win32api.GetUserName()
if test_user == 'SYSTEM':
user_name = 'SYSTEM'
elif get_sid_from_name(test_user) == 'S-1-5-18':
user_name = 'SYSTEM'
except pywintypes.error as exc:
raise CommandExecutionError(
'Failed to get current user: {0}'.format(exc[2]))