fix(win_function): handle other language

This commit is contained in:
Alkivi 2016-12-14 12:44:50 +01:00 committed by rallytime
parent 9e35f5dd08
commit e602f17e3d

View file

@ -142,9 +142,16 @@ 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()
sid, d, t = win32security.LookupAccountName('', test_user)
real_sid = user = win32security.ConvertSidToStringSid(sid)
if test_user == 'SYSTEM':
user_name = 'SYSTEM'
elif real_sid == 'S-1-5-18':
user_name = 'SYSTEM'
except pywintypes.error as exc:
raise CommandExecutionError(
'Failed to get current user: {0}'.format(exc[2]))