Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(string.Format("Getting the password for computer {0}", args[0]));
                AdmPwd.Types.PasswordInfo pwdData = PdsWrapper.GetLocalAdminPassword(ForestName: string.Empty, ComputerName: args[0], IncludePasswordHistory: false, ComputerIsDeleted: false);
                Console.WriteLine(string.Format("Password: {0}", pwdData.Password));
                Console.WriteLine(string.Format("Expires: {0}", pwdData.ExpirationTimestamp.ToString()));

                Console.Write("Resetting password ... ");

                PdsWrapper.ResetLocalAdminPassword(ForestName: string.Empty, ComputerName: args[0], WhenEffective: DateTime.Now);
                Console.WriteLine("done");
            }
            catch (AdmPwd.Types.PDSException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
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;

            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.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.GetManagedAccountPassword(null, adminAccountName, false);
                }
                else if (adminAccountName.Contains('@'))
                {
                    //upn
                    pwdInfo = PdsWrapper.GetManagedAccountPassword(null, adminAccountName, false);
                }
                else
                {
                    //local account
                    domainName = server;
                    if (adminAccountName == null)
                    {
                        //default admin name
                        adminAccountName = "administrator";
                    }
                    pwdInfo = PdsWrapper.GetLocalAdminPassword(null, server, 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);

                Application.Run(form);

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