Как получить отображаемое имя пользователя в Python + Windows в среде AD? [Дубликат]

# All the mumbo jumbo aside, here is an experiment 
# to illustrate why this is something useful 
# in the language of Python:
a = 15    # This could be read-only, should check docs

def test_1():
    b = a + 10    # It is perfectly ok to use 'a'
    print(b)

def test_2():
    a = a + 10    # Refrain from attempting to change 'a'
    print(a)

test_1()    # No error
test_2()    # UnboundLocalError: ...
0
задан Abhinav Kumar 27 March 2019 в 07:11
поделиться

1 ответ

Это то, что вы хотите?

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())

Второй сценарий

user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(),   win32api.GetUserName(), 2)
full_name = user_info["full_name"]
print(full_name)
0
ответ дан Xenobiologist 27 March 2019 в 07:11
поделиться
Другие вопросы по тегам:

Похожие вопросы: