mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
28 lines
864 B
C++
28 lines
864 B
C++
#pragma once
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#include <Windows.h>
|
|
#include <string>
|
|
|
|
#include "wil/resource.h"
|
|
#include <lmcons.h>
|
|
|
|
namespace
|
|
{
|
|
constexpr inline wchar_t POWERTOYS_MSI_MUTEX_NAME[] = L"Local\\PowerToyRunMutex";
|
|
constexpr inline wchar_t POWERTOYS_MSIX_MUTEX_NAME[] = L"Local\\PowerToyMSIXRunMutex";
|
|
constexpr inline wchar_t POWERTOYS_BOOTSTRAPPER_MUTEX_NAME[] = L"PowerToysBootstrapperMutex";
|
|
}
|
|
|
|
inline wil::unique_mutex_nothrow createAppMutex(std::wstring mutexName)
|
|
{
|
|
wchar_t username[UNLEN + 1];
|
|
DWORD username_length = UNLEN + 1;
|
|
GetUserNameW(username, &username_length);
|
|
mutexName += username;
|
|
wil::unique_mutex_nothrow result{ CreateMutexW(nullptr, TRUE, mutexName.c_str()) };
|
|
|
|
return GetLastError() == ERROR_ALREADY_EXISTS ? wil::unique_mutex_nothrow{} : std::move(result);
|
|
}
|