-1

I want to get the Full display name of user current logged in . I am on Active Directory login so usually I get username easily but I am looking for User's Display name.

path = os.path.join('..','Documents and Settings',getpass.getuser(),'Desktop') os.getlogin()

This does not works as it gives username not display name.

Abhinav Kumar
  • 177
  • 2
  • 5
  • 22

1 Answers1

2

Is this what you want?

import ctypes

def get_display_name():
    GetUserNameEx = ctypes.windll.secur32.GetUserNameExW
    NameDisplay = 3

    size = ctypes.pointer(ctypes.c_ulong(0))
    GetUserNameEx(NameDisplay, None, size)

    nameBuffer = ctypes.create_unicode_buffer(size.contents.value)
    GetUserNameEx(NameDisplay, nameBuffer, size)
    return nameBuffer.value

print(get_display_name())

Second script

user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(),   win32api.GetUserName(), 2)
full_name = user_info["full_name"]
print(full_name)
Xenobiologist
  • 2,091
  • 1
  • 12
  • 16