如何以编程方式更改我的Windows域密码?

Dee*_*tan 7 windows passwords dns

换句话说,如何更改我的密码而不通过" Ctrl+ Alt+ Del- > 更改密码 "界面.

通过编程方式我的意思是通过命令行工具,C#通过.NET库,通过Python进行COM调用,......无论什么都不涉及任何手动步骤,真的.

NET USER命令不合格,因为它要求我以域管理员权限运行.

Lei*_*fel 5

这是 Sjoerd 提供的代码的修改版本,它只更改一次密码,而不是循环更改多个密码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;

namespace ChangePassword
{
    class Program
    {
        static void Main(string[] args)
        {
            string Domain = Environment.UserDomainName;
            string User = Environment.UserName;

            if (args.Length < 2)
            {
                System.Console.WriteLine("Usage: ChangePassword OldPassword NewPassword [User]");
                System.Console.WriteLine("       -The domain is " + Domain + ".");
                System.Console.WriteLine("       -The user is " + User + " unless it is specified.");
                System.Environment.Exit(1);
            }
            string OldPassword = args[0];
            string NewPassword = args[1];
            if (args.Length == 3)
                User = args[2];

            DirectoryEntry entry = null;
            try {
                entry = new DirectoryEntry(@"WinNT://" + Domain + "/" + User + ",User");
            }
            catch (System.Reflection.TargetInvocationException e)
            {
                System.Console.WriteLine("Domain/User failed due to:");
                Exception cause = e.InnerException;
                System.Console.WriteLine(cause.Message);
                System.Environment.Exit(1);
            }

            try {
                entry.Invoke("ChangePassword", OldPassword, NewPassword);
            }
            catch (System.Reflection.TargetInvocationException e)
            {
                System.Console.WriteLine("Password change failed due to:");
                Exception cause = e.InnerException;
                System.Console.WriteLine(cause.Message);
                System.Environment.Exit(1);
            }
            System.Console.WriteLine("Ok.");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)