Skip to content

Commit

Permalink
[win] get ms account name
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplestStudio committed Nov 26, 2024
1 parent 0811157 commit ca31b6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions win-linux/defaults.pri
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ core_windows {
-lcredui \
-lnetapi32 \
-lcomctl32 \
-lnetapi32 \
-lrpcrt4
# -lOpenGL32

Expand Down
14 changes: 12 additions & 2 deletions win-linux/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
# include <QDesktopServices>
#include <windowsx.h>
# include <sddl.h>
# include <Lm.h>
#include "shlobj.h"
#include "lmcons.h"
#else
Expand Down Expand Up @@ -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() ) {
Expand Down

0 comments on commit ca31b6b

Please sign in to comment.