VB.net - Create a user group?

2019-09-03 19:17发布

I'm trying to create a user group named Maintenance_app using vb.net.

The code is:

Dim dom As New DirectoryEntry()
  Dim ou As DirectoryEntry = dom.Children.Find("")
  Dim grp As DirectoryEntry = ou.Children.Add("Maintenance_app", "group")
  grp.CommitChanges()

I receive the following error at the second line:

An unknown directory object was requested

What I'm doing wrong ?

1条回答
放我归山
2楼-- · 2019-09-03 19:57

If you want to work with Active Directory you need to understand the LDAP ADsPath.

In your case:

Dim dom as New DirectoryEntry
Dim ou as DirectoryEntry = dom.Children.Find("OU=yourOU")
Dim grp as DirectoryEntry = ou.Children.Add("CN=Maintenance_app", group")
grp.CommitChanges()

Or if you want the group on top level without an OU then just erase the 2nd line and change the 3rd line to:

Dim grp as DirectoryEntry = dom.Children.Add("CN=Maintenance_app", group")

As it seems that you are new to Active Directory here some Glossar:

DN = Distinguished Name

CN = Common Name

OU = Organizational Unit

DC = Domain Component

Formula example:

DN = "CN=Doe\, John,OU=Employees,OU=London,DC=fabrikam,DC=com"

Every single object in an Active Directory has its own exact DN.

查看更多
登录 后发表回答