Пример #1
0
        static int Worker(Params commandParams)
        {
            string domainName = null;

            if (commandParams.User.Contains("\\"))
            {
                string[] pairs = commandParams.User.Split('\\');
                domainName         = pairs[0];
                commandParams.User = pairs[1];
                if (domainName == ".")
                {
                    accountType = IdentityType.LocalComputerAdmin;
                }
            }
            if (commandParams.NoLocalProfile)
            {
                dwLogonFlags = LogonFlags.LOGON_NETCREDENTIALS_ONLY;
            }

            try
            {
                PasswordInfo pwdInfo = null;
                switch (accountType)
                {
                case IdentityType.ManagedDomainAccount:
                    pwdInfo = PdsWrapper.GetPassword(null, commandParams.User, accountType, false, false);
                    break;

                default:
                    pwdInfo = PdsWrapper.GetPassword(null, System.Environment.GetEnvironmentVariable("COMPUTERNAME"), accountType, false, false);
                    break;
                }

                StartupInfo si = new StartupInfo();
                si.cb = Marshal.SizeOf(si);
                ProcessInformation pi = new ProcessInformation();
                bool rslt             = Native.CreateProcessWithLogonW(commandParams.User, domainName, pwdInfo.Password, (uint)dwLogonFlags, null, commandParams.ProgramPath, (uint)(CreationFlags.CREATE_NEW_PROCESS_GROUP | CreationFlags.ABOVE_NORMAL_PRIORITY_CLASS), 0, null, ref si, out pi);
                if (!rslt)
                {
                    throw new System.ComponentModel.Win32Exception(Native.GetLastError());
                }
            }
            catch (PDSException ex)
            {
                Console.WriteLine($"ERROR: {ex.Message}");
                return(-1);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                Console.WriteLine($"ERROR: Failed to start process, Win32 return code: {ex.NativeErrorCode.ToString("X2")}");
                return(-2);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {ex.Message}");
                return(-3);
            }

            return(0);
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length > 0)
                {
                    Console.WriteLine(string.Format("Getting the password for computer {0}", args[0]));
                    AdmPwd.Types.PasswordInfo pwdData = PdsWrapper.GetPassword(ForestName: string.Empty, Identity: args[0], Type: IdentityType.LocalComputerAdmin, IncludePasswordHistory: false, IsDeleted: false);
                    Console.WriteLine(string.Format("Password: {0}", pwdData.Password));
                    Console.WriteLine(string.Format("Expires: {0}", pwdData.ExpirationTimestamp.ToString()));

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

                    //request immediate password reset
                    PdsWrapper.ResetPassword(ForestName: string.Empty, Identity: args[0], Type: IdentityType.LocalComputerAdmin, WhenEffective: DateTime.MinValue);
                    Console.WriteLine("done");
                }
                else
                {
                    Console.WriteLine("ERROR: You must pass computer name as parameter");
                }
            }
            catch (PDSException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(string.Format("Getting the password for computer {0}", args[0]));
                AdmPwd.Types.PasswordInfo pwdData = PdsWrapper.GetPassword(forestName: string.Empty, ComputerName: args[0], IncludePasswordHistory: false);
                Console.WriteLine(string.Format("Password: {0}", pwdData.Password));
                Console.WriteLine(string.Format("Expires: {0}", pwdData.ExpirationTimestamp.ToString()));

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

                PdsWrapper.ResetPassword(forestName: string.Empty, computerName: args[0], whenEffective: DateTime.Now);
                Console.WriteLine("done");
            }
            catch (FaultException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #4
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
            }
        }