久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 C# 中使用密碼創建 Active Directory 用戶

Creating Active Directory user with password in C#(在 C# 中使用密碼創建 Active Directory 用戶)
本文介紹了在 C# 中使用密碼創建 Active Directory 用戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找一種方法來創建 Active Directory 用戶并設置他們的密碼,最好不授予我的應用程序/服務域管理員權限.

I'm looking for a way to create Active Directory users and set their password, preferably without giving my application/service Domain Admin privileges.

我嘗試了以下方法:

DirectoryEntry newUser = _directoryEntry.Children.Add("CN=" + fullname, USER);
newUser.Properties["samAccountName"].Value = username;
newUser.Properties["userPassword"].Value = password;
newUser.Properties["mail"].Value = email;
newUser.CommitChanges();

用戶已創建,但似乎從未在用戶上設置密碼.

The user is created, but it seems the password is never set on the user.

有沒有人知道如何在創建用戶時最初設置用戶密碼?我知道

Does anyone have an idea on how to set the user's password initially when creating the user? I know about

.Invoke("SetPassword", new object[] { password })

但這需要我的代碼以域管理員權限運行.因為我真的沒有看到授予我的代碼域管理員權限的意義,只是為了設置初始密碼(我也允許用戶密碼重置,但那些在該特定用戶的上下文中運行),我希望有人有一個聰明的不需要我這樣做的解決方案.

But that requires my code to be run with Domain Admin privileges. As I don't really see the point to grant my code Domain Admin privileges, just to set the initial password (I also allow user password resets, but those run in the context of that particular user), I am hoping someone has a clever solution that doesn't require me to do so.

提前致謝!

推薦答案

現在您可以使用 System.DirectoryServices.AccountManagement 更輕松地完成整個過程(只要您使用的是 .Net 3.5):

You can do this whole process much easier now with System.DirectoryServices.AccountManagement (long as you're on .Net 3.5):

請參閱此處了解完整概要

以下是您的具體案例的快速示例:

Here's a quick example of your specific case:

using(var pc = new PrincipalContext(ContextType.Domain))
{
  using(var up = new UserPrincipal(pc))
  {
    up.SamAccountName = username;
    up.EmailAddress = email;
    up.SetPassword(password);
    up.Enabled = true;
    up.ExpirePasswordNow();
    up.Save();
  }
}

這篇關于在 C# 中使用密碼創建 Active Directory 用戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 日韩久久久久久久久久久 | 免费在线视频精品 | 欧美精品一区二区三区视频 | 久久99网站 | 亚洲国产中文字幕 | 日韩在线免费播放 | 久草在线| 久久久久久免费精品一区二区三区 | 国产99久久 | 天天操天天射天天 | 欧美在线激情 | 黄色免费网| 日本精品视频在线 | 久久伊人一区二区 | 99精品免费久久久久久日本 | 中文字幕在线视频网站 | 色播99| av中文在线 | 国产精品久久久久久婷婷天堂 | 欧美电影免费观看高清 | 国产精品国产三级国产aⅴ无密码 | 国产美女永久免费无遮挡 | 亚洲狠狠爱 | 亚洲精品在线观看视频 | 区一区二区三在线观看 | 国产精品永久免费视频 | 国产精品久久久久久久久免费 | 色吧久久 | 久久国产成人 | 欧美日韩精品一区二区天天拍 | 最新国产在线 | 亚洲精品一级 | 麻豆久久久 | 亚洲伦理自拍 | 在线观看欧美日韩视频 | 日韩精品视频一区二区三区 | 成人二区 | 亚洲激情在线观看 | 亚洲理论在线观看电影 | 亚洲视频在线看 | 毛片在线免费 |