UriPocForm.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Diagnostics;
  3. using System.Windows.Forms;
  4. namespace CustomUrlSchemeRegistrationPoC
  5. {
  6. public partial class UriPocForm : Form
  7. {
  8. public UriPocForm()
  9. {
  10. InitializeComponent();
  11. }
  12. private void InstallButton_Click(object sender, EventArgs e)
  13. {
  14. var registration = new CustomUriSchemeRegistration(SchemeTextBox.Text, DisplayTextBox.Text, Application.ExecutablePath);
  15. if (registration.Install(out var err)) MessageBox.Show("Success", "Install");
  16. else MessageBox.Show(err.ToString(), "Install");
  17. }
  18. private void UninstallButton_Click(object sender, EventArgs e)
  19. {
  20. var registration = new CustomUriSchemeRegistration(SchemeTextBox.Text, DisplayTextBox.Text, Application.ExecutablePath);
  21. if (registration.Uninstall(out var err)) MessageBox.Show("Success", "Uninstall");
  22. else MessageBox.Show(err.ToString(), "Uninstall");
  23. }
  24. private void TryCallButton_Click(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28. var process = Process.Start($"{SchemeTextBox.Text}://{TryCallArgsTextBox.Text}");
  29. if (null == process)
  30. {
  31. MessageBox.Show("Unknown result", "Try Call");
  32. }
  33. else
  34. {
  35. process.WaitForExit();
  36. MessageBox.Show("Success", "Try Call");
  37. }
  38. }
  39. catch (Exception err)
  40. {
  41. MessageBox.Show(err.ToString(), "Try Call");
  42. }
  43. }
  44. }
  45. }