换句话说,如何在不通过 “>更改密码按Ctrl + Alt键+德尔” 去更改密码。如何以编程方式更改我的Windows域密码?接口 -
通过编程方式,我的意思是通过命令行工具,C#通过.NET库,通过Python进行COM调用,......任何不涉及任何手动步骤,真的。
NET USER
命令不合格,因为它需要我以域管理员权限运行。
换句话说,如何在不通过 “>更改密码按Ctrl + Alt键+德尔” 去更改密码。如何以编程方式更改我的Windows域密码?接口 -
通过编程方式,我的意思是通过命令行工具,C#通过.NET库,通过Python进行COM调用,......任何不涉及任何手动步骤,真的。
NET USER
命令不合格,因为它需要我以域管理员权限运行。
这里是所提供的代码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.");
}
}
}
正是我的用例。 :) 谢谢! – Deestan 2010-06-08 11:38:53
该文章中的代码看起来可能会回答这个问题,但我不同意实际的文章,因为它没有提到它只适用于未设置* Minimum Password Age *的管理不善的系统。 – 2010-06-08 11:39:08
@ ho1谢谢。我将文章更改为包含有关密码最短使用期限的注释。 – Sjoerd 2010-06-08 12:02:54