[win] get ms account name

This commit is contained in:
SimplestStudio
2024-11-26 13:28:36 +02:00
parent 0811157b30
commit ca31b6b372
2 changed files with 13 additions and 2 deletions

View File

@ -304,6 +304,7 @@ core_windows {
-lcredui \
-lnetapi32 \
-lcomctl32 \
-lnetapi32 \
-lrpcrt4
# -lOpenGL32

View File

@ -56,6 +56,7 @@
# include <QDesktopServices>
#include <windowsx.h>
# include <sddl.h>
# include <Lm.h>
#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<USER_INFO_10*>(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() ) {