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