By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Having Trouble Populating A ListBox With Network Computer Names

P: n/a
Hi. I am using the following code to try and populate two list boxes.
The first, lstWorkgroups, is to show a list of the workgroups on my
network. The second, lstComputers, is to show a list of the computers
under each workgroup. This code works fine until it finds something it
doesn't like when searching for the computers within a workgroup. For
some reason, objFolder3.Items.Count and objFolder4.Items.Count get set
to zero, and there's no way to continue after that. If anyone could look
at my code and try to help, it would be appreciated.

Private Sub frmGetComp_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
objFolder =
objShell.NameSpace_(Shell32.ShellSpecialFolderCons tants.ssfNETWORK)
For i = 0 To (objFolder.Items.Count - 1)
If objFolder.Items().Item(i).Name.Equals_("Entire Network")
objFolder2 = CType(objFolder.Items().Item_(i).GetFolder,
For k = 0 To (objFolder2.Items.Count - 1)
objFolder2.Items().Item_(k).Name.Equals("Microsoft Windows Network")
objFolder3 =
CType(objFolder2.Items_().Item(k).GetFolder, Shell32.Folder)
For l = 0 To_(objFolder3.Items.Count - 1)

lstWorkgroups.Items.Add_(objFolder3.Items.Item(l). Name)
If objFolder3.Items.Item_(l).Name =
"Specific Workgroup Here" Then
objFolder4 =
CType_(objFolder3.Items.Item(l).GetFolder, Shell32.Folder)
For j = 0 To _(objFolder4.Items.Count -

lstComputers.Items.Add(objFolder4.Items.Item(j).Na me)
Catch ex As Exception
MessageBox.Show_("Your program
is screwed up!")
End Try
End If
End If
End If
End Sub
All of the objFolders shown here are declared as global, as is the
objShell. Also, the way the code is set is just to test to work with one
specific work group. If I can get one to work, I can get them all to
work. I know this might be confusing, and I apologize for that, but if
anyone has any ideas, please help!

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.