Skip to content

Commit

Permalink
Merge pull request 'Add feature: get MS account name' (#110) from fea…
Browse files Browse the repository at this point in the history
…ture/get-ms-account-name into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/desktop-apps/pulls/110
  • Loading branch information
Oleg Kozhukharenko committed Dec 4, 2024
2 parents fabc251 + ca31b6b commit c1c9aa3
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 c1c9aa3

Please sign in to comment.