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

在 C# 中使用密碼創(chuàng)建 Active Directory 用戶

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

問題描述

我正在尋找一種方法來創(chuàng)建 Active Directory 用戶并設(shè)置他們的密碼,最好不授予我的應(yīng)用程序/服務(wù)域管理員權(quán)限.

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();

用戶已創(chuàng)建,但似乎從未在用戶上設(shè)置密碼.

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

有沒有人知道如何在創(chuàng)建用戶時最初設(shè)置用戶密碼?我知道

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 })

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

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.

提前致謝!

推薦答案

現(xiàn)在您可以使用 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();
  }
}

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

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

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 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#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 久久久网 | 手机日韩| 亚洲国产精品久久久久秋霞不卡 | www.日韩 | 亚洲精品一区中文字幕乱码 | 欧美一级黄 | 国产 日韩 欧美 在线 | 国产高清视频 | 亚洲一区二区三区久久久 | 99精品欧美一区二区三区 | 欧美日韩福利视频 | 国产高清精品一区二区三区 | 91高清在线 | 99精品99| 天堂在线1 | 99精品久久久久 | 人人澡视频 | 97精品国产97久久久久久免费 | 爽爽免费视频 | 性欧美精品一区二区三区在线播放 | 蜜桃综合在线 | 免费能直接在线观看黄的视频 | 久久成人综合 | 99re在线视频 | 国产欧美一区二区三区久久 | 久久久无码精品亚洲日韩按摩 | 日日摸日日碰夜夜爽2015电影 | 久在线视频播放免费视频 | 亚洲精品中文字幕中文字幕 | 波多野结衣精品 | 免费观看成人av | 人人爱干 | 欧美日韩综合视频 | 99re国产视频 | 国产精品一区二区久久久久 | 成人午夜影院 | 日韩一二三区视频 | 国产精品毛片一区二区三区 | 欧美一区二区三区在线看 | 亚洲视频欧美视频 | 成av在线|