private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     ConsoleWrapper.Alloc();
     Log.Error(e.ExceptionObject);
     ConsoleWrapper.WriteLine("Error occured. Please check the log file for details");
     Environment.Exit(1);
 }
        private static void Uninstall()
        {
            ConsoleWrapper.Alloc();
            if (!RequireAdministratorPrivilages())
            {
                return;
            }

            Registry.ClassesRoot.DeleteSubKeyTree(REGISTRY_KEY_NAME, false);
            ConsoleWrapper.WriteLine("RDP Protocol Handler uninstalled.");
            Log.Info("RDP Protocol Handler uninstalled.");
        }
        private static void Install(bool prompt = true)
        {
            ConsoleWrapper.Alloc();

            if (!RequireAdministratorPrivilages())
            {
                return;
            }

            //if (prompt)
            //{
            //    ConsoleWrapper.Write("Do you want to install RDP Protocol handler? (for details use /?) [Y]es [N]o:");
            //    var result = ConsoleWrapper.ReadLine();
            //    if (result?.ToLower() != "y") return;
            //}

            Uninstall();

            //-- get assembly info
            var assembly        = Assembly.GetExecutingAssembly();
            var handlerLocation = assembly.Location;

            //-- create registy structure
            var rootKey        = Registry.ClassesRoot.CreateSubKey(REGISTRY_KEY_NAME);
            var defaultIconKey = rootKey?.CreateSubKey("DefaultIcon");
            var commandKey     = rootKey?.CreateSubKey("shell")?.CreateSubKey("open")?.CreateSubKey("command");

            rootKey?.SetValue("", "rdp:Remote Desktop Protocol");
            rootKey?.SetValue("URL Protocol", "");
            defaultIconKey?.SetValue("", @"C:\Windows\System32\mstsc.exe");
            commandKey?.SetValue("", $@"""{handlerLocation}"" ""%1""");

            //--
            Log.Info("RDP Protocol Handler installed");
            ConsoleWrapper.WriteLine("RDP Protocol Handler installed");
            ConsoleWrapper.WriteLine($"WARNING: Do not move this '{assembly.FullName}' to other location, otherwise handler will not work. If you change the location run installation process again.");
        }
 private static void Help()
 {
     ConsoleWrapper.Alloc();
     ConsoleWrapper.WriteLine("For help go to: https://github.com/konradsikorski/RdpProtocolHandler");
 }