The list of PC's in a neighborhood 
Author Message
 The list of PC's in a neighborhood

How to get the list of pc's connecteds in a LAN, like the Network
Neighborhood of Windows 95/98/NT.
Please, if someone knows about it, send me an e-mail. Thanks



Fri, 09 Mar 2001 03:00:00 GMT  
 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
    dw_ver_major As Long
    dw_ver_minor As Long
    dw_type As Long
    ptr_comment As Long
End Type

The different types of server to look for are SV_*, some are defined as
follows:

Public Const SV_TYPE_WORKSTATION = &H1
Public Const SV_TYPE_SERVER = &H2
Public Const SV_TYPE_SQLSERVER = &H4
Public Const SV_TYPE_DOMAIN_CTRL = &H8
Public Const SV_TYPE_DOMAIN_BACKUP = &H10
Public Const SV_TYPE_TIMESOURCE = &H20
Public Const SV_TYPE_AFP = &H40
Public Const SV_TYPE_NOVELL = &H80
Public Const SV_TYPE_NT = &H8000
Public Const SV_TYPE_ALL = &HFFFFFFFF

The routine (which will dump the results on a listbox control called List1)
is:-

Private Sub ListServers(lType As Long)

Dim lReturn As Long
Dim Server_Info As Long
Dim lEntries As Long
Dim lTotal As Long
Dim lMax As Long
Dim vResume As Variant
Dim tServer_info_101 As SERVER_INFO_101
Dim sServer As String
Dim sDomain As String
Dim lServerInfo101StructPtr As Long
Dim x As Long, i As Long
Dim bBuffer(512) As Byte

    Form1.List1.Clear

    lReturn = NetServerEnum( _
        ByVal 0&, _
        101, _
        Server_Info, _
        lMax, _
        lEntries, _
        lTotal, _
        ByVal lType, _
        sDomain, _
        vResume)

    If lReturn <> 0 Then
        MsgBox "Error " + Str$(lReturn) + " when trying to obtain server
list " + Str$(lTotal), vbOKOnly + vbExclamation
        Exit Sub
    End If

    x = 1
    lServerInfo101StructPtr = Server_Info

    Do While x <= lTotal

        RtlMoveMemory _
            tServer_info_101, _
            ByVal lServerInfo101StructPtr, _
            Len(tServer_info_101)

        lstrcpyW bBuffer(0), _
            tServer_info_101.ptr_name

        i = 0
        Do While bBuffer(i) <> 0
            sServer = sServer & _
                Chr$(bBuffer(i))
            i = i + 2
        Loop
       Form1.List1.Additem sServer
        DoEvents
        x = x + 1
sServer = ""
        lServerInfo101StructPtr = _
            lServerInfo101StructPtr + _
            Len(tServer_info_101)

    Loop

    lReturn = NetApiBufferFree(Server_Info)

End Sub

To use this, ensure that the routine ListServers is code in a form (Form1),
with a listbox (List1) on it. Call the routine and pass the server typr you
are looking for (eg ListServers SV_TYPE_WORKSTATION).

Cheers,

Andy


Quote:
>How to get the list of pc's connecteds in a LAN, like the Network
>Neighborhood of Windows 95/98/NT.
>Please, if someone knows about it, send me an e-mail. Thanks




Mon, 12 Mar 2001 03:00:00 GMT  
 The list of PC's in a neighborhood
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
    dw_ver_major As Long
    dw_ver_minor As Long
    dw_type As Long
    ptr_comment As Long
End Type

The different types of server to look for are SV_*, some are defined as
follows:

Public Const SV_TYPE_WORKSTATION = &H1
Public Const SV_TYPE_SERVER = &H2
Public Const SV_TYPE_SQLSERVER = &H4
Public Const SV_TYPE_DOMAIN_CTRL = &H8
Public Const SV_TYPE_DOMAIN_BACKUP = &H10
Public Const SV_TYPE_TIMESOURCE = &H20
Public Const SV_TYPE_AFP = &H40
Public Const SV_TYPE_NOVELL = &H80
Public Const SV_TYPE_NT = &H8000
Public Const SV_TYPE_ALL = &HFFFFFFFF

The routine (which will dump the results on a listbox control called
List1)
is:-

Private Sub ListServers(lType As Long)

Dim lReturn As Long
Dim Server_Info As Long
Dim lEntries As Long
Dim lTotal As Long
Dim lMax As Long
Dim vResume As Variant
Dim tServer_info_101 As SERVER_INFO_101
Dim sServer As String
Dim sDomain As String
Dim lServerInfo101StructPtr As Long
Dim x As Long, i As Long
Dim bBuffer(512) As Byte

    Form1.List1.Clear

    lReturn = NetServerEnum( _
        ByVal 0&, _
        101, _
        Server_Info, _
        lMax, _
        lEntries, _
        lTotal, _
        ByVal lType, _
        sDomain, _
        vResume)

    If lReturn <> 0 Then
        MsgBox "Error " + Str$(lReturn) + " when trying to obtain server
list " + Str$(lTotal), vbOKOnly + vbExclamation
        Exit Sub
    End If

    x = 1
    lServerInfo101StructPtr = Server_Info

    Do While x <= lTotal

        RtlMoveMemory _
            tServer_info_101, _
            ByVal lServerInfo101StructPtr, _
            Len(tServer_info_101)

        lstrcpyW bBuffer(0), _
            tServer_info_101.ptr_name

        i = 0
        Do While bBuffer(i) <> 0
            sServer = sServer & _
                Chr$(bBuffer(i))
            i = i + 2
        Loop
       Form1.List1.Additem sServer
        DoEvents
        x = x + 1
sServer = ""
        lServerInfo101StructPtr = _
            lServerInfo101StructPtr + _
            Len(tServer_info_101)

    Loop

    lReturn = NetApiBufferFree(Server_Info)

End Sub

To use this, ensure that the routine ListServers is code in a form
(Form1),
with a listbox (List1) on it. Call the routine and pass the server typr
you
are looking for (eg ListServers SV_TYPE_WORKSTATION).

Cheers,

Andy


Quote:
>How to get the list of pc's connecteds in a LAN, like the Network
>Neighborhood of Windows 95/98/NT.
>Please, if someone knows about it, send me an e-mail. Thanks




Fri, 16 Mar 2001 03:00:00 GMT  
 The list of PC's in a neighborhood
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 »



Sat, 17 Mar 2001 03:00:00 GMT  
 The list of PC's in a neighborhood
Hello,

After reading your post I tested some code I've been using on NT with Net
API's on a mixed NT and 95 network and it works fine. I can enumerate
Domains(workgroups), computers, and shares. What specifically doesn't work
under 95? I'm running OSR2... maybe that makes a difference?

Thanks,
RWK


You know what to do with the _NO_SPAM...

Quote:

>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).



Mon, 26 Mar 2001 03:00:00 GMT  
 The list of PC's in a neighborhood
Do you mean that you have used NetServerEnum from an NT system to enumerate
comuters that happen to be running Windows 95/98? If so, then yes that works
fine.

If you mean that you ran NetServerEnum from a Windows 95 system then I am a
little surprised as it should not be available to 95/95 OSR2 or 98

Cheers,

Andy


Quote:
>Hello,

>After reading your post I tested some code I've been using on NT with Net
>API's on a mixed NT and 95 network and it works fine. I can enumerate
>Domains(workgroups), computers, and shares. What specifically doesn't work
>under 95? I'm running OSR2... maybe that makes a difference?

>Thanks,
>RWK


>You know what to do with the _NO_SPAM...


>>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).



Tue, 03 Apr 2001 03:00:00 GMT  
 The list of PC's in a neighborhood


Quote:
>4th time posted, and counting...

>...<snip>...
<snip>
>End Sub

>To use this, ensure that the routine ListServers is code in a form (Form1),
>with a listbox (List1) on it. Call the routine and pass the server typr you
>are looking for (eg ListServers SV_TYPE_WORKSTATION).

>Cheers,

>Andy



>>How to get the list of pc's connecteds in a LAN, like the Network
>>Neighborhood of Windows 95/98/NT.
>>Please, if someone knows about it, send me an e-mail. Thanks


Do you have the code that can list the shares for each computer?

--
Dave Grey



Thu, 14 Jun 2001 03:00:00 GMT  
 The list of PC's in a neighborhood
Hi,

I have an example VB6 project that can do this using WNet functions (so it
will work on NT and 95).

Mail me if you want it.

Cheers,

Andy


Quote:


>>4th time posted, and counting...

>>...<snip>...
><snip>
>>End Sub

>>To use this, ensure that the routine ListServers is code in a form
(Form1),
>>with a listbox (List1) on it. Call the routine and pass the server typr
you
>>are looking for (eg ListServers SV_TYPE_WORKSTATION).

>>Cheers,

>>Andy



>>>How to get the list of pc's connecteds in a LAN, like the Network
>>>Neighborhood of Windows 95/98/NT.
>>>Please, if someone knows about it, send me an e-mail. Thanks

>Do you have the code that can list the shares for each computer?

>--
>Dave Grey



Sun, 17 Jun 2001 03:00:00 GMT  
 The list of PC's in a neighborhood


Quote:
>Hi,

>I have an example VB6 project that can do this using WNet functions (so it
>will work on NT and 95).

>Mail me if you want it.

>Cheers,

>Andy





>>>4th time posted, and counting...

>>>...<snip>...
>><snip>
>>>End Sub

>>>To use this, ensure that the routine ListServers is code in a form
>(Form1),
>>>with a listbox (List1) on it. Call the routine and pass the server typr
>you
>>>are looking for (eg ListServers SV_TYPE_WORKSTATION).

>>>Cheers,

>>>Andy



>>>>How to get the list of pc's connecteds in a LAN, like the Network
>>>>Neighborhood of Windows 95/98/NT.
>>>>Please, if someone knows about it, send me an e-mail. Thanks

>>Do you have the code that can list the shares for each computer?

>>--
>>Dave Grey

Sure. It shouldn't be hard to remove the needed code.

Cheers,
--
Dave Grey



Sun, 17 Jun 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Listing PC's on different domains from 1 pc

2. Store Network Neighborhood PC Names in Listbox

3. Populate list box of networked PC's

4. Listing PC's on an NT Network

5. Programmatically list PC's in workgroup

6. Programmatically handling 'Network Neighborhood' in VB5

7. Network Neighborhood in Drive List Box ??

8. Network Neighborhood in Drive List Box?

9. list network neighborhood

10. API to see the list of computers in Network Neighborhood

11. List Contents of Network Neighborhood

12. API to get list of Computers in Network Neighborhood

 

 
Powered by phpBB® Forum Software