質問

いのクエリは現在のドメインコントローラから次の変更ユーザーのパスワードになります。

(P)DCの名称を完全修飾名で指定する必要がある DC=pdc,DC=example,DC=com (どのように適切な名前などの表記は?)

どうでも使用できないC#?

役に立ちましたか?

解決 3

(System.DirectoryServices.AccountManagement.dllが必要です):

using (var context = new System.DirectoryServices.AccountManagement.PrincipalContext(ContextType.Domain))
{
    string server = context.ConnectedServer; // "pdc.examle.com"
    string[] splitted = server.Split('.'); // { "pdc", "example", "com" }
    IEnumerable<string> formatted = splitted.Select(s => String.Format("DC={0}", s));// { "DC=pdc", "DC=example", "DC=com" }
    string joined = String.Join(",", formatted); // "DC=pdc,DC=example,DC=com"

    // or just in one string

    string pdc = String.Join(",", context.ConnectedServer.Split('.').Select(s => String.Format("DC={0}", s)));
}

他のヒント

DomainControllerはあなたのマシンがない属しているドメインに存在する場合に情報を取得するには、より多くの何かを必要としています。

  DirectoryContext domainContext =  new DirectoryContext(DirectoryContextType.Domain, "targetDomainName", "validUserInDomain", "validUserPassword");

  var domain = System.DirectoryServices.ActiveDirectory.Domain.GetDomain(domainContext);
  var controller = domain.FindDomainController();

私たちは、内部アプリケーションのために、このようなものを使用しています。

DC=d,DC=r,DC=ABC,DC=com

のようなものを返す必要があります
public static string RetrieveRootDseDefaultNamingContext()
{
    String RootDsePath = "LDAP://RootDSE";
    const string DefaultNamingContextPropertyName = "defaultNamingContext";

    DirectoryEntry rootDse = new DirectoryEntry(RootDsePath)
    {
        AuthenticationType = AuthenticationTypes.Secure;
    };
    object propertyValue = rootDse.Properties[DefaultNamingContextPropertyName].Value;

    return propertyValue != null ? propertyValue.ToString() : null;
}

まとの交流のディレクトリにないと思いますか、 FSMO の役割に関することができます。変更したい場合は、トポロジーからプログラム(ない)、 DomainController クラスです。

変更したい場合はユーザーのパスワードを呼び出すことができこれらの行動はユーザオブジェクト活動のディレクトリの変化を適切に再現されています。

からコピーされた http://www.rootsilver.com/2007/08/how-to-change-a-user-password

public static void ChangePassword(string userName, string oldPassword, string newPassword)
{
        string path = "LDAP://CN=" + userName + ",CN=Users,DC=demo,DC=domain,DC=com";

        //Instantiate a new DirectoryEntry using an administrator uid/pwd
        //In real life, you'd store the admin uid/pwd  elsewhere
        DirectoryEntry directoryEntry = new DirectoryEntry(path, "administrator", "password");

        try
        {
           directoryEntry.Invoke("ChangePassword", new object[]{oldPassword, newPassword});
        }
        catch (Exception ex)  //TODO: catch a specific exception ! :)
        {
           Console.WriteLine(ex.Message);
        }

        Console.WriteLine("success");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top