Ejemplo n.º 1
0
 public void SetOptions(RdpOptions opts)
 {
     if (opts.RedirectDevices)
     {
         axRdpClient.AdvancedSettings7.RedirectDevices = true;
     }
     if (opts.RedirectDrives)
     {
         axRdpClient.AdvancedSettings7.RedirectDrives = true;
     }
     if (opts.RedirectPrinters)
     {
         axRdpClient.AdvancedSettings7.RedirectPrinters = true;
     }
     if (opts.RedirectSmartCards)
     {
         axRdpClient.AdvancedSettings7.RedirectSmartCards = true;
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string adminAccountName = null;
            string server           = null;
            string domainName       = null;
            ushort port             = 3389;

            var Options = new RdpOptions();

            foreach (string arg in args)
            {
                if (arg.StartsWith("/user:"******"/server:", StringComparison.CurrentCultureIgnoreCase))
                {
                    server = arg.Substring(8);
                    continue;
                }
                if (arg.StartsWith("/port:", StringComparison.CurrentCultureIgnoreCase))
                {
                    ushort.TryParse(arg.Substring(6), out port);
                    continue;
                }

                if (arg.Equals("/RedirectDrives", StringComparison.CurrentCultureIgnoreCase))
                {
                    Options.RedirectDrives = true;
                    continue;
                }
                if (arg.Equals("/RedirectPrinters", StringComparison.CurrentCultureIgnoreCase))
                {
                    Options.RedirectPrinters = true;
                    continue;
                }
                if (arg.Equals("/RedirectSmartCards", StringComparison.CurrentCultureIgnoreCase))
                {
                    Options.RedirectSmartCards = true;
                    continue;
                }
                if (arg.Equals("/RedirectDevices", StringComparison.CurrentCultureIgnoreCase))
                {
                    Options.RedirectDevices = true;
                    continue;
                }
                if (arg.Equals("/RedirectAll", StringComparison.CurrentCultureIgnoreCase))
                {
                    Options.RedirectDrives     = true;
                    Options.RedirectDevices    = true;
                    Options.RedirectPrinters   = true;
                    Options.RedirectSmartCards = true;
                    continue;
                }
                if (arg.StartsWith("/?", StringComparison.CurrentCultureIgnoreCase))
                {
                    Usage();
                    return;
                }
            }
            if (server == null)
            {
                Usage();
                return;
            }
            PasswordInfo pwdInfo = null;

            try
            {
                //user name to use
                if (adminAccountName.Contains('\\'))
                {
                    //domain\sAMAccountName
                    string[] pairs = adminAccountName.Split('\\');
                    domainName       = pairs[0];
                    adminAccountName = pairs[1];
                    pwdInfo          = PdsWrapper.GetPassword(null, adminAccountName, IdentityType.ManagedDomainAccount, false, false);
                }
                else if (adminAccountName.Contains('@'))
                {
                    //upn
                    pwdInfo = PdsWrapper.GetPassword(null, adminAccountName, IdentityType.ManagedDomainAccount, false, false);
                }
                else
                {
                    //local account
                    domainName = server;
                    if (adminAccountName == null)
                    {
                        //default admin name
                        adminAccountName = "administrator";
                    }
                    pwdInfo = PdsWrapper.GetPassword(null, server, IdentityType.LocalComputerAdmin, false, false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to retrieve password for account {adminAccountName}\nError: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                var form = new MainForm();

                var   cfg        = new Configuration();
                Int64 windowSize = cfg.LastWindowSize;

                if (windowSize > 0)
                {
                    form.SetSize(windowSize);
                }
                form.SetCredentials(adminAccountName, domainName, pwdInfo.Password);
                form.SetServerName(server, port);
                form.SetOptions(Options);

                Application.Run(form);

                cfg.LastWindowSize = form.GetSize();
                cfg.Update();
            }
            catch (Exception)
            {
                //do nothing now
            }
        }