Question Create a Computer in AD - Wrong Group used

charno

New member
Joined
May 8, 2008
Messages
1
Programming Experience
1-3
Hi,

When I create a Computer in Active Directory via the DirectoryServices, the Computer Object is in the wrong group (Domain Users instead of Domain Computers). This is a big problem, because a computer with the same name as the AD object can't join the Domain.

Does anybody have an idea how to define the default group for a new object? I can't change the group later in the application, because I have no rights in the groups Domain Users and Domain Computers.

When I create a computer object via the Management Console, everything works fine.

Here the Code I use to create the Workstation:

VB.NET:
    Private Sub createws()
        Dim de As New DirectoryServices.DirectoryEntry(Me.path)
        Dim computer As DirectoryServices.DirectoryEntry = de.Children.Add("cn=" & Me.hostname, "Computer")
        Dim val As Integer

        ' Change Details for the Account (Description set to Corporate rules)
        computer.Properties("sAMAccountName").Value = Me.hostname
        If Me.reserved Then
            computer.Properties("description").Value = "@reserved"
        Else
            computer.Properties("description").Value = Me.User & ", " & Me.Department & ", " & Me.Building & "/" & Me.Room & ", " & Me.App
        End If
        computer.CommitChanges()

        ' Activate Account
        val = CInt(computer.Properties("userAccountControl").Value)
        computer.Properties("userAccountControl").Value = val And Not &H2
        computer.CommitChanges()
    End Sub

If you need more information, please ask for it! I haven't an idea, which informations could be useful.

I hope you can help me!

Regards,
Charno
 
Back
Top