displaying computer name in listbox without "CN".

hamda000
hamda000 used Ask the Experts™
on
I found this code and it is working for me.
I'm trying to display a list of computer from a specific OU but in the listbox, I got the real name with the Common Name prior to the real name.

EXemple:

CN=COMPUTER NAME

Here is my code
-------------------------------------------------------------------------------------------------------------------
Imports System
Imports System.Net
Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory

Public Class frmMediaProjectorTest

Private Sub frmMediaProjectorTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub
 

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
        'Affiche la liste des ordinateurs du OU Médiatisation
       
        Dim domain As DirectoryEntry = New DirectoryEntry("LDAP://OU=ORDI-MEDIATISATION,ou=ORDINATEURS,OU=AD2008,DC=cegep-st-laurent,DC=qc,DC=ca")

        For Each child As DirectoryEntry In domain.Children
            'remplir la liste avec les nom des postes Médiatisation
            lstProjectors.Items.Add(child.Name).ToString()
        Next

    End Sub

   
    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        'Quitter le programme
        Me.Close()
    End Sub
End Class
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Architect in .Net
Commented:
Why don't simply remove the "CN=" part?

lstProjectors.Items.Add(child.Name.Replace("CN=", String.Empty)).ToString()

or

lstProjectors.Items.Add(child.Name.Substring(3)).ToString()

Hope that helps.

Author

Commented:
Thank you very much. It works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial