private async void Application_Startup(object sender, StartupEventArgs e) { InstallProtocol(); var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { Uri argUri; string command = ""; string pass = ""; string key = ""; if (Uri.TryCreate(args[1], UriKind.Absolute, out argUri)) { var decoder = new WwwFormUrlDecoder(argUri.Query); if (decoder.Any()) { foreach (var entry in decoder) { if (entry.Name == "comm") { command = entry.Value; } else if (entry.Name == "auth") { pass = entry.Value; } else if (entry.Name == "key") { key = entry.Value; } } } switch (command) { case "shutdown": if (await PasscodeHelper.Auth(pass, key)) { ShutdownHelper.ShutdownSystem(); } else { MessageBox.Show("Authentication failed", "Error"); } break; case "reboot": if (await PasscodeHelper.Auth(pass, key)) { ShutdownHelper.RebootSystem(); } else { MessageBox.Show("Authentication failed", "Error"); } break; } App.Current.Shutdown(); } } }
public MainWindow() { InitializeComponent(); var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { Uri argUri; if (Uri.TryCreate(args[1], UriKind.Absolute, out argUri)) { var decoder = new WwwFormUrlDecoder(argUri.Query); if (decoder.Any()) { InputUrI.Text = string.Empty; foreach (var entry in decoder) { InputUrI.Text += entry.Name + "=" + entry.Value + ","; inputs[entry.Name] = entry.Value; } InputUrI.Text = InputUrI.Text.Remove(InputUrI.Text.Length - 1); } } } }
private Dictionary <string, string> GetInputs() { Dictionary <string, string> inputs = new Dictionary <string, string>(); try { var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { Uri argUri; if (Uri.TryCreate(args[1], UriKind.Absolute, out argUri)) { var decoder = new WwwFormUrlDecoder(argUri.Query); if (decoder.Any()) { foreach (var entry in decoder) { inputs[entry.Name] = entry.Value; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(inputs); }