diff --git a/src/apps/deskflow-daemon/deskflow-daemon.cpp b/src/apps/deskflow-daemon/deskflow-daemon.cpp index 3be19a0af..b6788ab80 100644 --- a/src/apps/deskflow-daemon/deskflow-daemon.cpp +++ b/src/apps/deskflow-daemon/deskflow-daemon.cpp @@ -68,6 +68,13 @@ int main(int argc, char **argv) LOG_DEBUG("log level: %s", logLevel.c_str()); } +#if SYSAPI_WIN32 + // Show warning if not running as admin as daemon will behave differently. + if (!ArchMiscWindows::isProcessElevated()) { + LOG_WARN("not running as admin, some features may not work"); + } +#endif + switch (initResult) { using enum DaemonApp::InitResult; diff --git a/src/lib/arch/win32/ArchMiscWindows.cpp b/src/lib/arch/win32/ArchMiscWindows.cpp index 80efd379a..54e242e53 100644 --- a/src/lib/arch/win32/ArchMiscWindows.cpp +++ b/src/lib/arch/win32/ArchMiscWindows.cpp @@ -604,3 +604,29 @@ void ArchMiscWindows::guardRuntimeVersion() // NOSONAR - `noreturn` is not avail exit(1); } } + +bool ArchMiscWindows::isProcessElevated() +{ + LOG_DEBUG("checking if process is elevated"); + + HANDLE hToken = nullptr; + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) { + throw XArch(new XArchEvalWindows()); + } + + TOKEN_ELEVATION elevation; + + try { + DWORD dwSize = sizeof(TOKEN_ELEVATION); + if (!GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize)) { + throw XArch(new XArchEvalWindows()); + } + } catch (...) { + CloseHandle(hToken); + throw; + } + + const auto isElevated = elevation.TokenIsElevated; + LOG_DEBUG("process is %s", isElevated ? "elevated" : "not elevated"); + return isElevated; +} diff --git a/src/lib/arch/win32/ArchMiscWindows.h b/src/lib/arch/win32/ArchMiscWindows.h index ed9bf3602..651463bda 100644 --- a/src/lib/arch/win32/ArchMiscWindows.h +++ b/src/lib/arch/win32/ArchMiscWindows.h @@ -169,8 +169,12 @@ public: //! Saves the window instance for later use. static void setInstanceWin32(HINSTANCE instance); + //! Get the name of the active input desktop. static std::string getActiveDesktopName(); + //! Returns true if the process is running with elevated privileges (i.e. as admin). + static bool isProcessElevated(); + private: //! Open and return a registry key, closing the parent key static HKEY openKey(HKEY parent, const TCHAR *child, bool create);