From 4760547083aa5b3e832683c727a9a7a1adc02173 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sun, 8 Aug 2021 16:17:21 +0300 Subject: [PATCH] UI: ControlManager: Named pipe name is per user name. --- src/ui/control/controlmanager.cpp | 2 +- src/ui/util/osutil.cpp | 12 ++++++++++++ src/ui/util/osutil.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ui/control/controlmanager.cpp b/src/ui/control/controlmanager.cpp index de0c767a..c3eb9419 100644 --- a/src/ui/control/controlmanager.cpp +++ b/src/ui/control/controlmanager.cpp @@ -210,5 +210,5 @@ void ControlManager::close() QString ControlManager::getServerName(bool isService) { - return QLatin1String(APP_BASE) + (isService ? "Svc" : QString()) + "Pipe"; + return QLatin1String(APP_BASE) + (isService ? "Svc" : OsUtil::userName()) + "Pipe"; } diff --git a/src/ui/util/osutil.cpp b/src/ui/util/osutil.cpp index b88f34c9..92c30a39 100644 --- a/src/ui/util/osutil.cpp +++ b/src/ui/util/osutil.cpp @@ -10,6 +10,8 @@ #define WIN32_LEAN_AND_MEAN #include +#include + #include "processinfo.h" namespace { @@ -97,6 +99,16 @@ qint32 OsUtil::getTickCount() return qint32(GetTickCount()); } +QString OsUtil::userName() +{ + wchar_t buf[UNLEN + 1]; + DWORD len = UNLEN + 1; + if (GetUserNameW(buf, &len)) { + return QString::fromWCharArray(buf, int(len) - 1); // skip terminationg null char. + } + return QString(); +} + bool OsUtil::isUserAdmin() { SID_IDENTIFIER_AUTHORITY idAuth = SECURITY_NT_AUTHORITY; diff --git a/src/ui/util/osutil.h b/src/ui/util/osutil.h index cbc064ec..40d09521 100644 --- a/src/ui/util/osutil.h +++ b/src/ui/util/osutil.h @@ -30,6 +30,7 @@ public: static qint32 getTickCount(); + static QString userName(); static bool isUserAdmin(); static bool beep(BeepType type = BeepSimple);