0

使用以下代码:

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

    'see if it already exists
    If DirectoryEntry.Exists("LDAP://CN=" & AdEntry.Text & ",OU=" & Machinetype.Text & ",OU=Computers,OU=" & USlocation.Text & ",OU=North America,DC=company,DC=com") = True Then
        MsgBox("Object already exists")
    Else

        Try

            'Set the directory entry
            Dim de As New DirectoryEntry("LDAP://OU=" & Machinetype.Text & ",OU=Computers,OU=" & USlocation.Text & ",OU=North America,DC=company,DC=com")
            Dim newComputer As DirectoryEntry = de.Children.Add("CN=TESTER", "computer")

            newComputer.CommitChanges()
            MsgBox("Computer added!")

        Catch ex As Exception
            MsgBox("Error adding computer")
        End Try

    End If
End Sub

结束类

根据http://msdn.microsoft.com/en-us/library/ms180851(v=VS.80).aspx这应该可以工作,但它会返回一个异常。有什么我想念的吗?

4

0 回答 0