def get_windows_username():
 import ctypes
 try:
  advapi32 = ctypes.windll.advapi32
  GetUserName = getattr(advapi32, u'GetUserNameW')
 except AttributeError:
  pass
 else:
  buf = ctypes.create_unicode_buffer(257)
  n = ctypes.c_int(257)
  if GetUserName(buf, ctypes.byref(n)):
   return buf.value
 return get_unicode_windows_env_var(u'USERNAME')

def get_windows_username ( ) : import ctypes try : advapi32 = ctypes . windll . advapi32 GetUserName = getattr ( advapi32 , u'GetUserNameW' ) except AttributeError : pass else : buf = ctypes . create_unicode_buffer ( 257 ) n = ctypes . c_int ( 257 ) if GetUserName ( buf , ctypes . byref ( n ) ) : return buf . value return get_unicode_windows_env_var ( u'USERNAME' )
return the user name of the currently loggen in user as a unicode string .