コード例 #1
0
 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);
 }
コード例 #2
0
        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.");
        }
コード例 #3
0
        private static bool RequireAdministratorPrivilages()
        {
            var isAdmin = IsUserAdministrator();

            if (!isAdmin)
            {
                var oldColor = ConsoleWrapper.ForegroundColor;
                ConsoleWrapper.ForegroundColor = ConsoleColor.Red;
                ConsoleWrapper.WriteLine("You must be system administrator");
                ConsoleWrapper.ForegroundColor = oldColor;
                Log.Error("You must be system administrator");
            }

            return(isAdmin);
        }
コード例 #4
0
        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.");
        }
コード例 #5
0
 private static void Help()
 {
     ConsoleWrapper.Alloc();
     ConsoleWrapper.WriteLine("For help go to: https://github.com/konradsikorski/RdpProtocolHandler");
 }