2012-03-21 39 views
2

ユーザーをActive Directoryに追加するアプリケーションを作成しています。私はそれが代わりの「ユーザー」の共有フォルダに、共有フォルダでユーザーを追加しますしかしADLDAPを使用してADにユーザーを追加する

LDAP://celtestdomdc1.celtestdom.local/CN=Users,DC=celtestdom,DC=local 

に「ユーザー」共有フォルダに接続するには、このコードを使用しようとしています。 CN =ユーザーは「Users」フォルダに追加する必要がありますか?

おかげ

+0

あなたのケースではmarc_sが正しいと思います。コードを投稿すると、必要な変更が表示されることがあります。 – user489041

答えて

3

ユーザーを作成している場合、あなたは

  • でユーザーを作成したいコンテナに

    • バインドする必要があり、そのの子として新しいユーザーアカウントを作成しますコンテナ

    LDAPパスを設定するだけで、ではなく、はどこに行くのかを定義しています。

    このような何か試してみてください(C#サンプルを - VB.NETに変換するのは簡単でなければなりません):

    DirectoryEntry cnUsers = new DirectoryEntry("LDAP://CN=Users,DC=celtestdom,DC=local"); 
    
    // create a user directory entry in the container 
    DirectoryEntry newUser = container.Children.Add("cn=NewUserAccount", "user"); 
    
    // add the samAccountName mandatory attribute 
    newUser.Properties["sAMAccountName"].Value = "NewUser"; 
    
    // add any optional attributes 
    newUser.Properties["givenName"].Value = "User"; 
    newUser.Properties["sn"].Value = "One"; 
    
    // save to the directory 
    newUser.CommitChanges(); 
    
    // set a password for the user account 
    // using Invoke method and IadsUser.SetPassword 
    newUser.Invoke("SetPassword", new object[] { "pAssw0rdO1" }); 
    
    // require that the password must be changed on next logon 
    newUser.Properties["pwdLastSet"].Value = 0; 
    
    // save to the directory 
    newUser.CommitChanges(); 
    

    それとも、.NET 3.5以降を使用している場合、あなたはまた、新しいSystem.DirectoryServices.AccountManagement名前空間を使用することができますそれはたくさんのことをより簡単にします。

    その後、コードは少し単純になります。

    // create a context for a domain and define "base" container to use 
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, 
         "celtestdom", "CN=Users,DC=celtestdom,DC=local"); 
    
    // create a user principal object 
    UserPrincipal user = new UserPrincipal(ctx, "NewUser", "[email protected]", true); 
    
    // assign some properties to the user principal 
    user.GivenName = "User"; 
    user.Surname = "One"; 
    
    // force the user to change password at next logon 
    user.ExpirePasswordNow(); 
    
    // save the user to the directory 
    user.Save(); 
    

    ここSystem.DirectoryServices.AccountManagement(S.DS.AM)名前空間についての詳細チェックアウト:

  • 関連する問題