[PowerToys Run] Issues with elevation (#11775)

* Delegate creation of non elevated process

* Error handling

* nits

* Fix potential race condition

* Fix spelling

* Fix spelling

* Fix build
This commit is contained in:
Mykhailo Pylyp
2021-06-22 15:24:03 +03:00
committed by GitHub
parent 7e79654ee0
commit cf9f0ce6a9
6 changed files with 215 additions and 113 deletions

View File

@@ -44,12 +44,18 @@ namespace PowerLauncher.Helper
/// Suffix to the channel name.
/// </summary>
private const string ChannelNameSuffix = "SingeInstanceIPCChannel";
private const string InstanceMutexName = @"Local\PowerToys_Run_InstanceMutex";
/// <summary>
/// Gets or sets application mutex.
/// </summary>
internal static Mutex SingleInstanceMutex { get; set; }
internal static void CreateInstanceMutex()
{
SingleInstanceMutex = new Mutex(true, InstanceMutexName, out bool firstInstance);
}
/// <summary>
/// Checks if the instance of the application attempting to start is the first instance.
/// If not, activates the first instance.
@@ -57,14 +63,12 @@ namespace PowerLauncher.Helper
/// <returns>True if this is the first instance of the application.</returns>
internal static bool InitializeAsFirstInstance()
{
string mutexName = @"Local\PowerToys_Run_InstanceMutex";
// Build unique application Id and the IPC channel name.
string applicationIdentifier = mutexName + Environment.UserName;
string applicationIdentifier = InstanceMutexName + Environment.UserName;
string channelName = string.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix);
SingleInstanceMutex = new Mutex(true, mutexName, out bool firstInstance);
SingleInstanceMutex = new Mutex(true, InstanceMutexName, out bool firstInstance);
if (firstInstance)
{
_ = CreateRemoteService(channelName);