换句话说,如何在不使用"Ctrl+Alt+Del -> 更改密码"界面的情况下更改我的密码。
通过编程方式,我是指通过命令行工具、C#通过.NET库、Python通过COM调用等方式。真正不涉及任何手动步骤的任何方法都可以。
通过编程方式,我是指通过命令行工具、C#通过.NET库、Python通过COM调用等方式。真正不涉及任何手动步骤的任何方法都可以。
NET USER
命令不合适,因为它要求我以域管理员权限运行。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.");
}
}
}