From ca31b6b37252219f8bf497ea96cf7c1f64fac5d8 Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 26 Nov 2024 13:28:36 +0200 Subject: [PATCH] [win] get ms account name --- win-linux/defaults.pri | 1 + win-linux/src/utils.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/win-linux/defaults.pri b/win-linux/defaults.pri index 197607d3c..18a3884a0 100644 --- a/win-linux/defaults.pri +++ b/win-linux/defaults.pri @@ -304,6 +304,7 @@ core_windows { -lcredui \ -lnetapi32 \ -lcomctl32 \ + -lnetapi32 \ -lrpcrt4 # -lOpenGL32 diff --git a/win-linux/src/utils.cpp b/win-linux/src/utils.cpp index 1d232641e..38db714fb 100644 --- a/win-linux/src/utils.cpp +++ b/win-linux/src/utils.cpp @@ -56,6 +56,7 @@ # include #include # include +# include #include "shlobj.h" #include "lmcons.h" #else @@ -871,8 +872,17 @@ std::wstring Utils::systemUserName() WCHAR _env_name[UNLEN + 1]{0}; DWORD _size = UNLEN + 1; - return GetUserName(_env_name, &_size) ? - std::wstring(_env_name) : L"Unknown.User"; + if (GetUserName(_env_name, &_size)) { + LPBYTE buff = nullptr; + if (NetUserGetInfo(nullptr, _env_name, 10, &buff) == NERR_Success) { + std::wstring user_name(reinterpret_cast(buff)->usri10_full_name); + NetApiBufferFree(buff); + if (!user_name.empty()) + return user_name; + } + return _env_name; + } + return L"Unknown.User"; #else QString _env_name = qgetenv("USER"); if ( _env_name.isEmpty() ) {