Quite right - Net* APIs are only available on NT.
I have been messing about with ADSI to achieve this and the code below works
on Win 95/98 (you need to install ADSI - see www.15seconds.com for info on
this).
As this group does not allow binary, the code only is posted. The VB project
needs to have a reference to 'Active DS Type Library'. Also, I have a form
(frmMain) with the following controls:-
lvMain (list view control)
tbMain (Tool bar)
imgLvMainSmall (image list)
imgLvMainLarge (image list)
imgTbMain (image list)
And a menu option called mnuViewHidden
You can do away with the tool bar and image lists (if you cut out the code
that sets the icons for lvMain).
Cheers,
Andy
Code from frmMain:-
Option Explicit
Dim sDomain As String
Dim sComputer As String
Dim lLevel As Long
Private Sub Form_Load()
Dim itmX As ListItem
With Me
.MousePointer = vbHourglass
.Move (Screen.Width - .Width) \ 2, _
(Screen.Height - .Height) \ 2
.Caption = "Network Neighborhood"
.lvMain.View = lvwList
.lvMain.ColumnHeaders. _
Add , , "Name", _
(Me.lvMain.Width) / 2
.lvMain.ColumnHeaders. _
Add , , "Comment", _
(Me.lvMain.Width) / 2
.tbMain.Buttons("vwList").Value = tbrPressed
.Show
GetDomainsList
.MousePointer = vbNormal
End With
End Sub
Private Sub lvMain_DblClick()
Dim sObject As String
Dim lIndex As Long
lIndex = Me.lvMain.SelectedItem.Index
Me.MousePointer = vbHourglass
sObject = Me.lvMain.ListItems(lIndex)
Select Case Me.lvMain.SelectedItem.SmallIcon
Case "Domain"
EnumerateDomain sObject
sDomain = sObject
Case "Computer"
EnumerateComputer sObject
sComputer = sObject
Case "Share"
EnumerateShare sComputer, sObject
End Select
Me.MousePointer = vbNormal
End Sub
Private Sub mnuViewHidden_Click()
mnuViewHidden.Checked = Not mnuViewHidden.Checked
If lLevel = 3 Then
Me.MousePointer = vbHourglass
EnumerateComputer sComputer
Me.MousePointer = vbNormal
End If
End Sub
Private Sub tbMain_ButtonClick(ByVal Button As ComctlLib.Button)
Select Case Button.Key
Case "vwDetails"
Me.lvMain.View = lvwReport
Case "vwList"
Me.lvMain.View = lvwList
Case "vwLarge"
Me.lvMain.View = lvwIcon
Case "vwSmall"
Me.lvMain.View = lvwSmallIcon
Case "UpLevel"
Me.MousePointer = vbHourglass
Select Case lLevel
Case 4
EnumerateComputer sComputer
Case 3
EnumerateDomain sDomain
Case 2
GetDomainsList
End Select
Me.MousePointer = vbNormal
End Select
End Sub
Private Sub GetDomainsList()
Dim cNT As IADsContainer
Dim cDomain As IADsDomain
Dim childNT As IADs
Dim childDomain As IADs
Dim sDomain As String
Dim itmX As ListItem
'
' Start at the WinNT level - could use LDAP etc.
'
ClearLV
lLevel = 1
Set cNT = GetObject("WinNT:")
cNT.Filter = Array("Domain")
For Each childNT In cNT
If Not (childNT Is Nothing) Then
sDomain = childNT.Name
Set itmX = _
Me.lvMain.ListItems. _
Add(, , sDomain)
itmX.SmallIcon = "Domain"
itmX.Icon = "Domain"
DoEvents
End If
Next childNT
End Sub
Sub ClearLV()
Dim lCount As Long
Dim lTotal As Long
lTotal = Me.lvMain.ListItems.Count
lCount = 1
If lTotal < 1 Then Exit Sub
Do
Me.lvMain.ListItems.Remove 1
'itmX.Selected = True
'Set itmX = Me.lvJobs.ListItems.Remove lCount
lCount = lCount + 1
Loop Until lCount > lTotal
End Sub
Private Sub EnumerateDomain(sDom As String)
Dim cDomain As IADsDomain
Dim childDomain As IADs
Dim sDomain As String
Dim itmX As ListItem
Dim cComputer As IADsComputer
Dim childComputer As IADs
Dim sDesc As String
Dim lErr As Long
ClearLV
lLevel = 2
'
' Set the Domain container to that of the current domain name
'
Set cDomain = GetObject("WinNT://" & sDom)
cDomain.Filter = Array("Computer")
For Each childDomain In cDomain
sDesc = ""
On Error Resume Next
Set cComputer = GetObject("WinNT://" & childDomain.Name)
If Err = 0 Then sDesc = cComputer.OperatingSystem + " " +
cComputer.OperatingSystemVersion
'If Err = 0 Then sdesc=cComputer.Get("Description")
If Desc <> "" Then
Set itmX = _
Me.lvMain.ListItems. _
Add(, , childDomain.Name)
itmX.SmallIcon = "Computer"
itmX.Icon = "Computer"
itmX.SubItems(1) = sDesc
DoEvents
End If
Next childDomain
End Sub
Private Sub EnumerateComputer(sComp As String)
Dim itmX As ListItem
Dim sDesc As String
Dim lErr As Long
Dim cLanMan As IADsFileService
Dim cFileShare As IADsFileShare
Dim childFileshare As IADs
Dim sShare As String
Dim bShow As Boolean
ClearLV
lLevel = 3
'
' Set the Domain container to that of the current domain name
'
On Error Resume Next
Set cLanMan = GetObject("WinNT://" & sComp & "/lanmanserver")
'cDomain.Filter = Array("Computer")
For Each cFileShare In cLanMan
If Not (cFileShare Is Nothing) Then
sShare = cFileShare.Name
sDesc = cFileShare.Description
If Right$(sShare, 1) = "$" Then
If Me.mnuViewHidden.Checked Then
bShow = True
Else
bShow = False
End If
Else
bShow = True
End If
If bShow Then
Set itmX = _
Me.lvMain.ListItems. _
Add(, , sShare)
itmX.SmallIcon = "Share"
itmX.Icon = "Share"
itmX.SubItems(1) = sDesc
DoEvents
End If
End If
Next cFileShare
End Sub
Private Sub EnumerateShare(sComp, sShareName As String)
Dim itmX As ListItem
Dim sDesc As String
Dim lErr As Long
Dim cLanMan As IADsFileService
Dim cFileShare As IADsFileShare
Dim childFileshare As IADs
Dim sShare As String
Dim bShow As Boolean
Dim sFile As String
Dim sSharePath As String
ClearLV
lLevel = 4
'
' Set the Domain container to that of the current domain name
'
On Error Resume Next
Set cLanMan = GetObject("WinNT://" & sComp & "/lanmanserver")
'cDomain.Filter = Array("Computer")
For Each cFileShare In cLanMan
If Not (cFileShare Is Nothing) Then
sShare = cFileShare.Name
If sShare = sShareName Then
'MsgBox cFileShare.Path
sSharePath = cFileShare.Path
If Right$(sSharePath, 1) = "\" Then
sFile = Dir$(sSharePath & "*.*", vbDirectory)
Else
sFile = Dir$(sSharePath & "\*.*", vbDirectory)
End If
If sFile <> "" Then
Do Until sFile = ""
Set itmX = _
Me.lvMain.ListItems. _
Add(, , sFile)
itmX.SmallIcon = "Directory"
itmX.Icon = "Directory"
itmX.SubItems(1) = "Folder"
DoEvents
sFile = Dir$()
Loop
End If
'
If Right$(sSharePath, 1) = "\" Then
sFile = Dir$(sSharePath & "*.*")
Else
sFile = Dir$(sSharePath & "\*.*")
End If
If sFile <> "" Then
Do Until sFile = ""
Set itmX = _
Me.lvMain.ListItems. _
Add(, , sFile)
itmX.SmallIcon = "File"
itmX.Icon = "File"
itmX.SubItems(1) = "File"
DoEvents
sFile = Dir$()
Loop
End If
End If
End If
Next cFileShare
Exit Sub
End Sub
Quote:
>How can I do this from Win95?
>I've readed that NetApi32 doesn't work with Win95.
>Thanks.
>-----Mensaje original-----
>Expuesto a las: jueves 24 de septiembre de 1998 6:00
>Expuesto en: networks
>Conversacin: The list of PC's in a neighborhood
>Asunto: Re: The list of PC's in a neighborhood
>4th time posted, and counting...
>...<snip>...
>I have a VB project that uses this functionality to find out the last
>time
>users logged on to the domain. Rather than post this project to the
>group,
>I have snipped the code that looks for servers....
>Below is the way I do it. The routine ListServers will enumerate the
>servers of a given type (the type is passed to the function). The
>results
>are placed on a listbox control on the form (in this case).
>The functions that need to be declared are:
>Public Declare Function NetServerEnum _
> Lib "netapi32.dll" ( _
> vServername As Any, _
> ByVal lLevel As Long, _
> vBufptr As Any, _
> lPrefmaxlen As Long, _
> lEntriesRead As Long, _
> lTotalEntries As Long, _
> vServerType As Any, _
> ByVal sDomain As String, _
> vResumeHandle As Any) As Long
>Public Declare Sub RtlMoveMemory _
> Lib "Kernel32" ( _
> dest As Any, _
> Vsrc As Any, _
> ByVal lSize&)
>Public Declare Sub lstrcpyW _
> Lib "Kernel32" ( _
> vDest As Any, _
> ByVal sSrc As Any)
>The data structure required is:
>Public Type SERVER_INFO_101
> dw_platform_id As Long
> ptr_name As Long
...
read more »