Basically i have a wizard so a user can setup the web app correctly when installed.

This requires them to enter details on a server which houses their database.

I would like to return a list of current paths in the local network for ease which they could select etc and also be able to enter manually if they have an alternative setup.

I just want to return all server paths which the current computer has found on its local area network. can this be done? I figured it would be under My.Network..... but to no avail. Please give me a hand if you have managed to achieve this before.

Recommended Answers

All 6 Replies

Hi there Fungus1487. Hmmm, I have not tried this before myself but I think the answer may lie in this article:

Hope that helps. Its a rather large article I am afraid but deals with accessing local and network resources.

Hey there majestic0110. Thanks for the reply. I have taken a good look through the article to no avail. I dont think it quite hits home on the concept i am trying to get working. After alot of browsing i have come across some nasty approaches to the technique i am looking to use.

What i require is a list of all computers on a local network domain so in turn i can get there individual IP addresses.

I have found plenty of advice in getting IP addresses of computers in the same domain using their computer names but this requires the application to know all the names of the computers in the network to begin with.

As of yet still have not found anything which looks tidy and im starting to doubt there is a "tidy" way to do this.

Alot of approaches are using "LDAP" but i frequently recieve a "Server is not operational error" wheneve rusing this approach. this example shows what i am attempting to do.

Again thanks for your reply and if you can be of any help it would be great.

Ok after a couple of hours looking into this problem i have come up with a solution which works just about everywhere i have tested it. I have stripped it to its bare bones and im sorry about the lack of commenting. I have wrote all this up in a nice wrapper Class to handle all the messy business behind the scenes yet posting this up here would be too cumbersome. If someone would like me to send them the wrapper class id be happy to. Simply contact me.

Ill Post below for anybody else who may have a similiar problem.

Method to Get Computer names and IP Address's in a domain
This method uses the LDAP protocol and requires the use of active directory

' Change "yourdomainname" to quite simply the domain you wish to query
Dim strLdap As String = "LDAP://yourdomainname"
Using dirEntry As New System.DirectoryServices.DirectoryEntry(strLdap)

    ' Create a new Search Result Collection to hold the returned values
    Dim dirSearcRes As System.DirectoryServices.SearchResultCollection = Nothing
    Using dirSearch As New System.DirectoryServices.DirectorySearcher(dirEntry)
        dirSearch.Filter = "(objectClass=computer)" ' Filter computers
        dirSearcRes = dirSearch.FindAll
    End Using

    ' Loop through search results
    For Each resSearch As System.DirectoryServices.SearchResult In dirSearcRes
            Using resEntry As DirectoryServices.DirectoryEntry = resSearch.GetDirectoryEntry
                ' Do what you wish with the following computer name and IP Address variables
                Dim strComputerName As String = resEntry.Name.Substring(3),
                Dim strIpAddress As String = System.Net.Dns.GetHostEntry(strComputerName).AddressList(0).ToString
            End Using
        Catch ex As Exception ' Catches computers with no name
        End Try
End Using

If you dont have active directory to work with then you can use the following two methods to find local computers.
The following method is faster than the last method but the next method only works for computers in a workgroup.

Using dirEntry As New System.DirectoryServices.DirectoryEntry()

    ' Create the WinNT query changing the "workgroupname" to your required workgroup
    Dim strNT As String = "WinNT://workgroupname"
    dirEntry.Path = strNT

    For Each dirChild As System.DirectoryServices.DirectoryEntry In dirEntry.Children()
        If dirChild.SchemaClassName = "Computer" Then 

            ' Do whatever with the computer name variable
            Dim strComputerName As String = dirChild.Name
        End If

End Using

And the final method seems to work everywhere i have tried it but requires the most time and resources. It is also what i deem the messiest due to having to rely on an external process. From researching this i have found (i may be wrong) that The "net.exe" executable is installed as default on all Windows platforms.

Using proNet As New System.Diagnostics.Process ' Start the net.exe process
    proNet.StartInfo.FileName = "net.exe"
    proNet.StartInfo.CreateNoWindow = True
    proNet.StartInfo.Arguments = "view"
    proNet.StartInfo.RedirectStandardOutput = True
    proNet.StartInfo.UseShellExecute = False
    proNet.StartInfo.RedirectStandardError = True

    Using strRead As New System.IO.StreamReader(proNet.StandardOutput.BaseStream, proNet.StandardOutput.CurrentEncoding)
        While Not strRead.EndOfStream ' Read results
            Dim strLine As String = strRead.ReadLine
            If strLine.StartsWith(CChar("\\")) Then
                ' Do whatever with the computer name variables
                Dim strComputerName As String = strLine.Substring(2)
            End If
        End While
    End Using

End Using

Nice one, have been trying to find some help for you. So I take it that it all works fine now?

commented: Thanks for the continued help +2

Yer it actually is running brilliantly.

Thanks for all your help.

It just a shame that it requires a mixture of all the above methods to get something that works across all major windows OS versions and network setups. Ah well.

Glad you got a fix there in the end. thanks for sharing the solution :) sorry I was not more help lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.