Checking for System Names

NigelRocks used Ask the Experts™

What is the best way to check whether a given system name already exists (Windows XP, VB.NET)?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Meir RivkinFull stack Software Engineer

already exists where?


In the system.
check if already exists in Active Directory? Asuming your are using AD:

If not using active directory, you could use a ping command: but when the system is not powered on you get no reply, so possible errors.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


I'm trying to do it with the attached code, but it appears to hang on the For Each line.
    Private Function ExistsSystemUserName(ByVal userName As String) As Boolean
        Dim bUserExists As Boolean
        Dim oDirectoryEntry As System.DirectoryServices.DirectoryEntry = _
        New System.DirectoryServices.DirectoryEntry("WinNT://{Server}")
        bUserExists = False
        For Each child As DirectoryEntry In oDirectoryEntry.Children
            If child.SchemaClassName = "User" Then
                If child.Name = userName Then
                    bUserExists = True
                End If
            End If
        Return bUserExists
    End Function

Open in new window

Do you have a windows domain using active directory?
change <<DirectoryEntry("WinNT://{Server}")>>
to <<DirectoryEntry("LDAP://DC=Steve,DC=Schofield,DC=com")>> but change with your values of the domain.

You changed into change DirectoryEntry("WinNT://{Server}")  
What did you try to accomplish with that?


Someone I work with dug up some code that uses that as the argument to DirectoryEntry.  I'm completely new to this, so I'm stabbing in the dark.  How do I find the LDAP server here?
Normally ldap server should be one of your domain controllers (they are working as ldap.)
could it be that {server} must be replaced with something in your code? or is some kind of variable?

else you can specify your domain with the domain name (using ldap://DC=) . this way you don't have to specify a server. It will try to locate one itself.

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