Set Windows/AD password so that it “never expires”?

前端 未结 3 538
没有蜡笔的小新
没有蜡笔的小新 2020-12-21 05:39

Here is my code:

using (DirectoryEntry AD = new DirectoryEntry(\"WinNT://\" + Environment.MachineName +    \",computer\"))
{
   DirectoryEntry NewUser = AD.C         


        
3条回答
  •  遥遥无期
    2020-12-21 06:13

    *EDITED

    For domain accounts:

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

    For local accounts:

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

提交回复
热议问题