簡體   English   中英

ActiveDirectory本地計算機帳戶管理-C#

[英]ActiveDirectory Local Machine Account management - C#

我發布了一個有關LDAP帳戶管理的問題,但是在探索了這個問題之后,我就沒有了。 我設法找到了兩種在計算機上創建用戶的方法,但是我發現其中一種方法比另一種方法更加整潔,但是,我不確定如何將第一個選項完全轉換為第二個選項。

這是我的第一個解決方案:

        Process MyProc = new Process();
        MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
        MyProc.StartInfo.FileName = "net.exe";
        MyProc.StartInfo.UseShellExecute = false;
        MyProc.StartInfo.RedirectStandardError = true;
        MyProc.StartInfo.RedirectStandardInput = true;
        MyProc.StartInfo.RedirectStandardOutput = true;
        MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

        MyProc.StartInfo.Arguments = string.Format(@" user {0} {1} /ADD /ACTIVE:YES /EXPIRES:NEVER /FULLNAME:{0}"" /PASSWORDCHG:NO /PASSWORDREQ:YES", username, password);

        MyProc.Start();
        MyProc.WaitForExit();
        int exit = MyProc.ExitCode;

        MyProc.Close();

        return exit == 0;

這是我的第二個(首選)解決方案:

        DirectoryEntry root = GetDELocalRoot();
        DirectoryEntry user = root.Children.Add(username, "user");
        //TODO: Always Active
        //TODO: Never Expires
        //TODO: No Password Change
        //TODO: Password Required
        user.Properties["description"].Value = "Account for running the MicaService and handling updates.";
        user.Invoke("SetPassword", new object[] { password });

        user.CommitChanges();
        user.Close();

我想在我的TODO中映射所有設置:從第一個解決方案到第二個更整潔的解決方案。

我也嘗試過以下行:

user.Properties["userAccountControl"].Value = ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT | ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE | ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;

但這不起作用,因為該屬性在緩存中不存在。

注意:GetDELocalRoot()=返回新的DirectoryEntry(“ WinNT://” + Environment.MachineName);

感謝您的輸入!

問候

特里斯

查閱我的朋友Richard Mueller的網站 ,該網站上有很多有用的信息和參考資料,介紹了這兩個提供程序(本地計算機帳戶的WinNT與網絡帳戶的LDAP)所提供的內容。

還有一個Excel表格,其中包含WinNT提供程序公開的所有屬性 -比LDAP提供程序少得多,因此我不確定是否能夠設置要查找的所有屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM