diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 7cd5223a50..c19d2f22d5 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "AppHost.h" #include "resource.h" @@ -275,7 +276,7 @@ AppHost* WindowEmperor::_mostRecentWindow() const noexcept void WindowEmperor::HandleCommandlineArgs(int nCmdShow) { std::wstring windowClassName; - windowClassName.reserve(47); // "Windows Terminal Preview Admin 0123456789012345" + windowClassName.reserve(64); // "Windows Terminal Preview Admin 0123456789012345 0123456789012345" #if defined(WT_BRANDING_RELEASE) windowClassName.append(L"Windows Terminal"); #elif defined(WT_BRANDING_PREVIEW) @@ -300,6 +301,18 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow) #endif } + { + wil::unique_handle processToken{ GetCurrentProcessToken() }; + const auto userTokenInfo{ wil::get_token_information(processToken.get()) }; + const auto sidLength{ GetLengthSid(userTokenInfo->User.Sid) }; + const auto hash{ til::hash(userTokenInfo->User.Sid, sidLength) }; +#ifdef _WIN64 + fmt::format_to(std::back_inserter(windowClassName), FMT_COMPILE(L" {:016x}"), hash); +#else + fmt::format_to(std::back_inserter(windowClassName), FMT_COMPILE(L" {:08x}"), hash); +#endif + } + // Windows Terminal is a single-instance application. Either acquire ownership // over the mutex, or hand off the command line to the existing instance. const auto mutex = acquireMutexOrAttemptHandoff(windowClassName.c_str(), nCmdShow);