Beispiel #1
0
        private static int ExecuteFromCommandLine(string[] args)
        {
            var options = new ProgramOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return(ReturnCodes.ArgumentsError);
            }
            try
            {
                var p = new PasswordChanger(
                    new CommandLinePasswordChangerSource(),
                    new PrincipalDomainContextFactory());
                p.ChangePassword(options);
                Console.Error.WriteLine("Password changed.");
                return(ReturnCodes.Ok);
            }
            catch (Exception e)
            {
                if (options.Verbose)
                {
                    Console.Error.WriteLine(e);
                }
                else
                {
                    Console.Error.WriteLine(e.Message);
                }

                return(ReturnCodes.ExecutionError);
            }
        }
Beispiel #2
0
        internal static int ExecuteFromCommandLine(string[] args, bool consoleMode = true, SecureString oldPwd = null, SecureString newPwd = null)
        {
            var options = new ProgramOptions()
            {
                ConsoleMode = consoleMode,
                OldPassword = oldPwd,
                NewPassword = newPwd
            };

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return(ReturnCodes.ArgumentsError);
            }

            try
            {
                var p = new PasswordChanger(
                    new CommandLinePasswordChangerSource(),
                    new PrincipalDomainContextFactory());
                p.ChangePassword(options);
                Log = "Password changed.";
                Console.Error.WriteLine(Log);
                return(ReturnCodes.Ok);
            }
            catch (Exception e)
            {
                if (options.Verbose)
                {
                    Log = e.Message;
                    Console.Error.WriteLine(e);
                }
                else
                {
                    Log = e.Message;
                    Console.Error.WriteLine(e.Message);
                }

                return(ReturnCodes.ExecutionError);
            }
        }