Hancorp
asked on
Network Computer, Share and Printer Browser
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.
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.
ASKER
I must admit bob, I don't know anything about the WMI.
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("objectC lass=compu ter")
For Each currentComputer As SearchResult In searchComputers.FindAll()
Dim nameComputer As String = currentComputer.Properties ("Name")(0 )
listComputers.Add(nameComp uter, nameComputer)
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return listComputers
End Function 'EnumerateNetworkComputers '
Bob
(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(
Dim listComputers As SortedList = New SortedList
Try
Dim searchComputers As DirectorySearcher = New DirectorySearcher("objectC
For Each currentComputer As SearchResult In searchComputers.FindAll()
Dim nameComputer As String = currentComputer.Properties
listComputers.Add(nameComp
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return listComputers
End Function 'EnumerateNetworkComputers
Bob
ASKER
Bob, I tried this and it failed on the line:
- For Each currentComputer As SearchResult In searchComputers.FindAll()
The error message is:
System.Runtime.InteropServ ices.COMEx ception (0x8007054B): The specified domain either does not exist or could not be contacted
at System.DirectoryServices.D irectoryEn try.Bind(B oolean throwIfFail)
at System.DirectoryServices.D irectoryEn try.Bind()
at System.DirectoryServices.D irectoryEn try.get_Ad sObject()
at System.DirectoryServices.P ropertyVal ueCollecti on.Populat eList()
at System.DirectoryServices.P ropertyVal ueCollecti on..ctor(D irectoryEn try entry, String propertyName)
at System.DirectoryServices.P ropertyCol lection.ge t_Item(Str ing propertyName)
at System.DirectoryServices.D irectorySe archer.get _SearchRoo t()
at System.DirectoryServices.D irectorySe archer.Fin dAll(Boole an findMoreThanOne)
at System.DirectoryServices.D irectorySe archer.Fin dAll()
at WMI.Form1.EnumerateNetwork Computers( ) 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.
- For Each currentComputer As SearchResult In searchComputers.FindAll()
The error message is:
System.Runtime.InteropServ
at System.DirectoryServices.D
at System.DirectoryServices.D
at System.DirectoryServices.D
at System.DirectoryServices.P
at System.DirectoryServices.P
at System.DirectoryServices.P
at System.DirectoryServices.D
at System.DirectoryServices.D
at System.DirectoryServices.D
at WMI.Form1.EnumerateNetwork
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.
Do you have Active Directory services on your local domain (i.e. Windows 2000 Server)?
Bob
Bob
ASKER
Yes Bob, I've just checked my COM references. ActiveDS is available under COM references.
Hai,
Check this link
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=741&lngWId=10
Systems on Local Network :-
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
https://www.experts-exchange.com/questions/21064750/Find-servers-and-workstations-on-local-network.html
Printers List :-
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
Dim strprinters As String
For Each strprinters In System.Drawing.Printing.Pr interSetti ngs.Instal ledPrinter s
ComboBox1.Items.Add(strpri nters)
Next
Network Shares Browser :-
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
Dim shi As ShareCollection = ShareCollection.LocalShare s
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
Check this link
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=741&lngWId=10
Systems on Local Network :-
--------------------------
https://www.experts-exchange.com/questions/21064750/Find-servers-and-workstations-on-local-network.html
Printers List :-
--------------------------
Dim strprinters As String
For Each strprinters In System.Drawing.Printing.Pr
ComboBox1.Items.Add(strpri
Next
Network Shares Browser :-
--------------------------
Dim shi As ShareCollection = ShareCollection.LocalShare
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
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(
Hope it helps you.
Bye
Ajai
ASKER
Ajai, will look into these. Thanks.
ASKER
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.
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.
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.MsgB ox(MyDialo g.Selected Path)
End If
Hope it helps you.
Bye
Ajai
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.MsgB
End If
Hope it helps you.
Bye
Ajai
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ajai,
Tried this on a Windows 2000 intranet and it works fine. Nice work.
Tried this on a Windows 2000 intranet and it works fine. Nice work.
Hai,
Most welcome.
Bye
Ajai
Most welcome.
Bye
Ajai
Bob