小编Cal*_*che的帖子

使用LDAP和C#设置Active Directory帐户过期

我想将新用户帐户设置为在创建后的90天内到期.这是我创建用户并设置所有内容的代码.一切正常,除了我试图将其设置为过期的最后一个块.

            DirectoryEntry newUser = dirEntry.Children.Add("CN=" + cnUser, "user");
            newUser.Properties["samAccountName"].Value = cnUser;
            newUser.Properties["userPrincipalName"].Value = cnUser;
            newUser.Properties["pwdLastSet"].Value = 0;
            newUser.CommitChanges();

            //Changes Password
            String passwrd = userPassword.ToString();
            newUser.Invoke("SetPassword", new object[] { passwrd });
            newUser.CommitChanges();

            //Sets User Account to Change Passowrd on new login
            newUser.Properties["pwdLastSet"].Value = 0;
            newUser.CommitChanges();

            //Enables account
            newUser.Properties["userAccountControl"].Value = (int)newUser.Properties["userAccountControl"].Value & ~0x2;
            newUser.CommitChanges();

            //Set the account to expire in 90 days
            var dt1 = DateTime.Today.AddDays(90);
            newUser.Properties["accountExpires"].Value = dt1.ToFileTime().ToString();
            newUser.CommitChanges();
Run Code Online (Sandbox Code Playgroud)

关于如何开展工作的任何建议?

谢谢

c# active-directory

4
推荐指数
2
解决办法
8017
查看次数

标签 统计

active-directory ×1

c# ×1