[個人作品]LDAP連線測試

來源:互聯網
上載者:User
這是我一年半前為了讓人測驗可不可以連AD寫的。

開發環境:Window XP
開發工具:Visual Stutio 2003(後來用Visual Stutio 2005重新編譯過)
開發語言:VB.NET
開發時間:95年1月

源始檔下載

執行畫面

程式說明

 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim domain As String = Me.TextBox1.Text
        Dim username As String = Me.TextBox2.Text
        Dim password As String = Me.TextBox3.Text

        Try
            Dim ad As New System.DirectoryServices.DirectoryEntry("LDAP://" & domain, username, password)
            st += ad.Name & vbCrLf
            ShowAD(ad, 0)
        Catch ex As Exception
            MessageBox.Show("輸入錯誤或無法讀取AD")
            Exit Sub
        End Try
        MessageBox.Show("測試正常" + vbCrLf + st)
        Application.Exit()
    End Sub
    Sub ShowAD()Sub ShowAD(ByVal ad As System.DirectoryServices.DirectoryEntry, ByVal level As Integer)
        For Each adChildren As System.DirectoryServices.DirectoryEntry In ad.Children
            If Me.ComboBox1.SelectedIndex = -1 Then
                st &= Microsoft.VisualBasic.Strings.StrDup(level, "-") & adChildren.Name & ";" & adChildren.SchemaClassName & vbCrLf
                If Me.CheckBox1.Checked = True Then
                    For Each ItemName As String In adChildren.Properties.PropertyNames
                        For Each items As Object In adChildren.Properties(ItemName)
                            st &= Microsoft.VisualBasic.Strings.StrDup(level + 1, "-") & ItemName & ":"
                            Try
                                st &= items & vbCrLf
                            Catch ex As Exception
                                st &= "無法繫結" & vbCrLf
                            End Try
                        Next
                    Next
                End If
            ElseIf adChildren.SchemaClassName = Me.ComboBox1.SelectedItem Then
                st &= Microsoft.VisualBasic.Strings.StrDup(level, "-") & adChildren.Name & ";" & adChildren.SchemaClassName & vbCrLf
                If Me.CheckBox1.Checked = True Then
                    For Each ItemName As String In adChildren.Properties.PropertyNames
                        For Each items As Object In adChildren.Properties(ItemName)
                            st &= Microsoft.VisualBasic.Strings.StrDup(level + 1, "-") & ItemName & ":"
                            Try
                                st &= items & vbCrLf
                            Catch ex As Exception
                                st &= "無法繫結" & vbCrLf
                            End Try
                        Next
                    Next
                End If
            End If

            ShowAD(adChildren, level + 1)
        Next
    End Sub

.NET跟LDAP(註一)是使用System.DirectoryServices.DirectoryEntry類別
建構式的格式如下
Dim ad As New System.DirectoryServices.DirectoryEntry("LDAP://" & domain, username, password)
當連結正常後再呼叫ShowAD取出子節點資訊

註一LDAP(Lightweight Directory Access Protocol)輕型目錄訪問協議

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.