本文介绍了设置Windows/AD密码,使其“永不过期"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

using (DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName +    ",computer"))
{
   DirectoryEntry NewUser = AD.Children.Add(username, "user");
   string password = username + "123";
   NewUser.Invoke("SetPassword", new object[] { password });
   NewUser.CommitChanges();
   NewUser.Close();
   DirectoryEntry grp;
   grp = AD.Children.Find(groupname, "group");
   if (grp != null)
    {
      grp.Invoke("Add", new object[] { NewUser.Path.ToString() });
    }
}

我想做的是创建一个Windows用户并设置密码永不过期,但是我不知道该怎么做?

And what i want to do is to create a windows user and set the password never expired ,But i do not know how to do this ?

推荐答案

*编辑

对于域帐户:

int NON_EXPIRE_FLAG = 0x10000;
val = (int) NewUser.Properties["userAccountControl"].Value;
NewUser.Properties["userAccountControl"].Value = val | NON_EXPIRE_FLAG;
NewUser.CommitChanges();

对于本地帐户:

我相信您会使用"UserFlags"代替userAccountControl

I believe you'd use "UserFlags" instead of userAccountControl

这篇关于设置Windows/AD密码,使其“永不过期"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 14:54