使用以下代码:
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,这应该有效,但它会返回一个例外。有什么我想念的吗?