appMutex.h
1 #pragma once 2 #ifndef WIN32_LEAN_AND_MEAN 3 #define WIN32_LEAN_AND_MEAN 4 #endif 5 #include <Windows.h> 6 #include <string> 7 8 #include "wil/resource.h" 9 #include <lmcons.h> 10 11 namespace 12 { 13 constexpr inline wchar_t POWERTOYS_MSI_MUTEX_NAME[] = L"Local\\PowerToys_Runner_MSI_InstanceMutex"; 14 constexpr inline wchar_t POWERTOYS_BOOTSTRAPPER_MUTEX_NAME[] = L"Local\\PowerToys_Bootstrapper_InstanceMutex"; 15 } 16 17 inline wil::unique_mutex_nothrow createAppMutex(const std::wstring& mutexName) 18 { 19 wil::unique_mutex_nothrow result{ CreateMutexW(nullptr, TRUE, mutexName.c_str()) }; 20 21 return GetLastError() == ERROR_ALREADY_EXISTS ? wil::unique_mutex_nothrow{} : std::move(result); 22 }