Checking for System Names

NigelRocks
NigelRocks used Ask the Experts™
on
Experts,

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

Do more with

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

Commented:
already exists where?

Author

Commented:
In the system.
Commented:
check if already exists in Active Directory? Asuming your are using AD:
http://aspalliance.com/801_CodeSnip_Get_a_complete_computer_list_from_Active_Directory_using_NET_20

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!

Author

Commented:
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
        Next
 
        Return bUserExists
 
    End Function

Open in new window

3_S
Commented:
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?

Author

Commented:
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?
3_S
Commented:
Normally ldap server should be one of your domain controllers (they are working as ldap.)
DirectoryEntry("WinNT://srv1.domain.com)  
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