[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Network Computer, Share and Printer Browser

Posted on 2004-08-06
13
Medium Priority
?
1,110 Views
Last Modified: 2009-07-29
Can you please provide me with a complete working combined solution for VB.Net 2002/2003, that displays a networked computer browser, printer browser, and network share browser.  The solution should use the Windows API.  

I have tried to code this myself, but I cannot get the Windows API to return the name.  For some reason, the API function returns only the first letter of the item I have selected, even though I have assigned a buffer of 260 characters.

This solution should work on both Windows 2000 and Windows-XP.

Your help in this matter will be greatly appreciated.
0
Comment
Question by:Hancorp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11738684
Do you know anything about Windows Management Instrumentation (WMI)?

Bob
0
 

Author Comment

by:Hancorp
ID: 11738795
I must admit bob, I don't know anything about the WMI.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11739136
I'm sorry, did I say WMI, I meant to say Active Directory:)  Here is an example:

 (1) Add a reference to the project for System.DirectoryServices.

 (2) Add a line at the top of the module where you put the code:

           Imports System.DirectoryServices

 (3) Add the following code to either a class or a form:

 Public Function EnumerateNetworkComputers() As SortedList

    Dim listComputers As SortedList = New SortedList

    Try

      Dim searchComputers As DirectorySearcher = New DirectorySearcher("objectClass=computer")

      For Each currentComputer As SearchResult In searchComputers.FindAll()

        Dim nameComputer As String = currentComputer.Properties("Name")(0)

        listComputers.Add(nameComputer, nameComputer)

      Next

    Catch ex As Exception

      MsgBox(ex.ToString)

    End Try

    Return listComputers

  End Function 'EnumerateNetworkComputers'


Bob
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Hancorp
ID: 11739599
Bob, I tried this and it failed on the line:

 - For Each currentComputer As SearchResult In searchComputers.FindAll()

The error message is:

System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at System.DirectoryServices.DirectorySearcher.get_SearchRoot()
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindAll()
   at WMI.Form1.EnumerateNetworkComputers() in C:\Test\Form1.vb:line 291

Am I getting this error because I need to get a list of directories (networks) and then for each network, loop through the computers on that network.  If so how do I do this, and can this be adapted to get either printers or network shares.

Hancorp.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11739605
Do you have Active Directory services on your local domain (i.e. Windows 2000 Server)?

Bob
0
 

Author Comment

by:Hancorp
ID: 11740025
Yes Bob, I've just checked my COM references. ActiveDS is available under COM references.
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 11741703
Hai,

Check this link
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=741&lngWId=10

Systems on Local Network :-
-----------------------------------------------------------------------------------------------------------------------------------------------
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21064750.html

Printers List :-
-----------------------------------------------------------------------------------------------------------------------------------------------
       Dim strprinters As String
        For Each strprinters In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            ComboBox1.Items.Add(strprinters)
        Next

Network Shares Browser :-
-----------------------------------------------------------------------------------------------------------------------------------------------
Dim shi As ShareCollection =  ShareCollection.LocalShares
If Not shi Is Nothing Then
    Dim si As Share
    For Each si In shi
        Console.WriteLine("{0}: {1} [{2}]",
            si.ShareType, si, si.Path)
 
        ' If this is a file-system share, try to
        ' list the first five subfolders.
        ' NB: If the share is on a removable device,
        ' you could get "Not ready" or "Access denied"
        ' exceptions.
        If si.IsFileSystem Then
            Try
                Dim d As System.IO.DirectoryInfo =  si.Root
                Dim Flds() As System.IO.DirectoryInfo =  d.GetDirectories()
                    Dim i As Integer
                    For  i = 0 To  Flds.Length And i < 5- 1  Step  i + 1
                          Console.WriteLine("\t{0} - {1}", i, Flds(i).FullName)
                    Next
 
                Console.WriteLine()
            Catch ex As Exception
                Console.WriteLine("\tError listing {0}:\n\t{1}\n",
                    si, ex.Message)
            End Try
        End If
    Next
Else
    Console.WriteLine("Unable to enumerate the local shares.")
End If
 
' Resolve local paths to UNC paths.
Console.WriteLine("{0} = {1}", fileName, ShareCollection.PathToUnc(fileName))

Hope it helps you.
Bye
Ajai
0
 

Author Comment

by:Hancorp
ID: 11742063
Ajai, will look into these.  Thanks.
0
 

Author Comment

by:Hancorp
ID: 11747385
Ajai and Bob, thanks guys.  I appreciate your help and the resources you have given me are excellent and do work.

Unfortunately, the company I work for will not move on the original specification that I have to work on.  The specification is as follows:

Through the use of the Win32 API, call the FolderBrowser dialog to enable users on both Windows 2000 and Windows XP to browse for network shared resources such as computers, printers, and files.  

I have been given 1 week in which to complete this task and I am struggling.  I have given other alternatives, such as those you have mentioned but they have been rejected.  

If you do know how to implement the Windows FolderBrowser using the Windows API, I would be very greatful.

Thanks again for the help you've already given.
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 11749990
Hai,

There is Folder Browser control available on .NET you can use that to open folders.

Sample code for opening folderborwser window.
        Dim MyDialog As New FolderBrowserDialog
        ' Sets the default location
        MyDialog.SelectedPath = "C:\"

        ' Update the text box folder if the user clicks OK
        If (MyDialog.ShowDialog() = DialogResult.OK) Then
             microsoft.VisualBasic.MsgBox(MyDialog.SelectedPath)
        End If

Hope it helps you.
Bye
Ajai
0
 
LVL 11

Accepted Solution

by:
ajaikumarr earned 2000 total points
ID: 11750004
0
 

Author Comment

by:Hancorp
ID: 11751428
Thanks Ajai,
Tried this on a Windows 2000 intranet and it works fine.  Nice work.
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 11751606
Hai,

Most welcome.

Bye
Ajai
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question