2020-04-08 05:19:33 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-06-11 01:58:34 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
using System.Windows;
|
2020-04-24 08:11:02 +08:00
|
|
|
|
using interop;
|
2020-06-19 03:56:12 +08:00
|
|
|
|
using ManagedCommon;
|
2020-05-06 01:02:31 +08:00
|
|
|
|
using Windows.UI.Popups;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Runner
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2020-05-14 17:36:27 +08:00
|
|
|
|
// Quantity of arguments
|
|
|
|
|
private const int ArgumentsQty = 5;
|
|
|
|
|
|
2020-04-08 05:19:33 +08:00
|
|
|
|
// Create an instance of the IPC wrapper.
|
2020-04-24 08:11:02 +08:00
|
|
|
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
|
2020-05-06 01:02:31 +08:00
|
|
|
|
public static bool IsElevated { get; set; }
|
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
|
public static bool IsUserAnAdmin { get; set; }
|
|
|
|
|
|
2020-06-11 01:58:34 +08:00
|
|
|
|
public static int PowerToysPID { get; set; }
|
|
|
|
|
|
2020-04-11 06:22:07 +08:00
|
|
|
|
[STAThread]
|
2020-04-08 05:19:33 +08:00
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
using (new UI.App())
|
|
|
|
|
{
|
|
|
|
|
App app = new App();
|
|
|
|
|
app.InitializeComponent();
|
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
|
if (args.Length >= ArgumentsQty)
|
2020-04-08 05:19:33 +08:00
|
|
|
|
{
|
2020-06-11 01:58:34 +08:00
|
|
|
|
int.TryParse(args[2], out int powerToysPID);
|
|
|
|
|
PowerToysPID = powerToysPID;
|
|
|
|
|
|
2020-05-06 01:02:31 +08:00
|
|
|
|
if (args[4] == "true")
|
|
|
|
|
{
|
|
|
|
|
IsElevated = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IsElevated = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
|
if (args[5] == "true")
|
|
|
|
|
{
|
|
|
|
|
IsUserAnAdmin = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IsUserAnAdmin = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 07:03:50 +08:00
|
|
|
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () => {
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
});
|
2020-06-11 01:58:34 +08:00
|
|
|
|
|
2020-04-24 08:11:02 +08:00
|
|
|
|
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
|
|
|
|
|
ipcmanager.Start();
|
2020-04-08 05:19:33 +08:00
|
|
|
|
app.Run();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"The application cannot be run as a standalone process. Please start the application through the runner.",
|
|
|
|
|
"Forbidden",
|
|
|
|
|
MessageBoxButton.OK);
|
|
|
|
|
app.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 08:11:02 +08:00
|
|
|
|
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
2020-04-08 05:19:33 +08:00
|
|
|
|
{
|
|
|
|
|
return ipcmanager;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|