Results 1 to 6 of 6

Thread: Listing Network Neighbourhood

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Australia
    Posts
    10

    Lightbulb

    Was just wondering if its possible to create a listing of all the systems visible in the Network Neighbourhood for your average Windows Networking LAN using VB...

    Anyone got any ideas on this?

    - Reprise
    "Hello, I would like to buy a fish licence please..."

  2. #2
    Lively Member The_Fog's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Posts
    65

    Not exactly, but close..

    I'm also looking for a way to list the network neighborhood, so if you hear anything, I would be very happy if you could share the information with me.

    One way to solve it(The one I use) is to create a list with comp. that are soupposed to be there, and then have a function to try and connect to all of these. Those that are succesfull will be added to the "Avaliable" list.
    Anyway.. That's one way to solve it.. Not a very good one, but it works..

    Hopes this helps.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Australia
    Posts
    10
    Yeah no worries If anyone gives me the slightest hint of a good way of doing it I'll let you know.

    - Reprise

  4. #4
    Lively Member The_Fog's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Posts
    65

    Talking Find Network

    check out http://www.planet-source-code.com
    Search for "DomainTree". you should end up downloading a program called "DoaminTree". This little progg lists all avaliable computers/domaind/workgroups on the network. Included sourcecode. Works great!
    They will try to steal everything you own,
    It goes on and on and on...


    Pain - On and On

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Australia
    Posts
    10
    Sweet Thanx heaps man...

    - Reprise

  6. #6
    Addicted Member
    Join Date
    Aug 2000
    Location
    Adelaide - Australia
    Posts
    150
    Code:
    'Paste this into a module 
    
                                                 Option Explicit 
    
                                                 Public Type NETRESOURCE 
                                                 dwScope As Long 
                                                 dwType As Long 
                                                 dwDisplayType As Long 
                                                 dwUsage As Long 
                                                 lpLocalName As Long 
                                                 lpRemoteName As Long 
                                                 lpComment As Long 
                                                 lpProvider As Long 
                                                 End Type 
    
                                                 Public Declare Function WNetOpenEnum Lib "mpr.dll" Alias _ 
                                                 "WNetOpenEnumA" ( _ 
                                                 ByVal dwScope As Long, _ 
                                                 ByVal dwType As Long, _ 
                                                 ByVal dwUsage As Long, _ 
                                                 lpNetResource As Any, _ 
                                                 lphEnum As Long) As Long 
    
                                                 Public Declare Function WNetEnumResource Lib "mpr.dll" Alias _ 
                                                 "WNetEnumResourceA" ( _ 
                                                 ByVal hEnum As Long, _ 
                                                 lpcCount As Long, _ 
                                                 ByVal lpBuffer As Long, _ 
                                                 lpBufferSize As Long) As Long 
    
                                                 Public Declare Function WNetCloseEnum Lib "mpr.dll" ( _ 
                                                 ByVal hEnum As Long) As Long 
    
                                                 'RESOURCE ENUMERATION. 
                                                 Public Const RESOURCE_CONNECTED = &H1 
                                                 Public Const RESOURCE_GLOBALNET = &H2 
                                                 Public Const RESOURCE_REMEMBERED = &H3 
    
                                                 Public Const RESOURCETYPE_ANY = &H0 
                                                 Public Const RESOURCETYPE_DISK = &H1 
                                                 Public Const RESOURCETYPE_PRINT = &H2 
                                                 Public Const RESOURCETYPE_UNKNOWN = &HFFFF 
    
                                                 Public Const RESOURCEUSAGE_CONNECTABLE = &H1 
                                                 Public Const RESOURCEUSAGE_CONTAINER = &H2 
                                                 Public Const RESOURCEUSAGE_RESERVED = &H80000000 
    
                                                 Private Const GMEM_FIXED = &H0 
                                                 Private Const GMEM_ZEROINIT = &H40 
                                                 Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT) 
    
                                                 Private Declare Function GlobalAlloc Lib "KERNEL32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long 
                                                 Private Declare Function GlobalFree Lib "KERNEL32" (ByVal hMem As Long) As Long 
                                                 Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long) 
                                                 Private Declare Function CopyPointer2String Lib "KERNEL32" Alias "lstrcpyA" (ByVal NewString As String, ByVal OldString As Long) As Long 
    
                                                 Public Sub DoNetEnum() 
                                                 Dim hEnum As Long, lpBuff As Long, NR As NETRESOURCE 
                                                 Dim cbBuff As Long, cCount As Long 
                                                 Dim p As Long, res As Long, i As Long 
    
                                                 'Setup the NETRESOURCE input structure. 
                                                 NR.lpRemoteName = 0 
                                                 cbBuff = 10000 
                                                 cCount = &HFFFFFFFF 
    
    
                                                 'Open a Net enumeration operation handle: hEnum. 
                                                 res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum) 
    
                                                 If res = 0 Then 
                                                 'Create a buffer large enough for the results. 
                                                 '100 00 bytes should be sufficient. 
                                                 lpBuff = GlobalAlloc(GPTR, cbBuff) 
                                                 'Call the enumeration function. 
                                                 res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff) 
                                                 If res = 0 Then 
                                                 p = lpBuff 
                                                 'WNetEnumResource fills the buffer with an array of 
                                                 'NETRESOURCE structures. Walk through the list and print 
                                                 'each local and remote name. 
                                                 For i = 1 To cCount 
                                                 ' All we get back are the Global Network Containers --- Enumerate each of these 
                                                 CopyMemory NR, ByVal p, LenB(NR) 
                                                 Form1.Show 
                                                 Form1.List1.AddItem "Network Name " & PointerToString(NR.lpRemoteName) 
    
                                                 DoNetEnum2 NR 
                                                 p = p + LenB(NR) 
                                                 Next i 
                                                 End If 
                                                 If lpBuff <> 0 Then GlobalFree (lpBuff) 
                                                 WNetCloseEnum (hEnum) 'Close the enumeration 
                                                 End If 
                                                 End Sub 
    
                                                 Private Function PointerToString(p As Long) As String 
                                                 'The values returned in the NETRESOURCE structures are pointers to 
                                                 'ANSI strings so they need to be converted to Visual Basic Strings. 
                                                 Dim s As String 
                                                 s = String(255, Chr$(0)) 
                                                 CopyPointer2String s, p 
                                                 PointerToString = Left(s, InStr(s, Chr$(0)) - 1) 
                                                 End Function 
    
                                                 Public Sub DoNetEnum2(NR As NETRESOURCE) 
                                                 Dim hEnum As Long, lpBuff As Long 
                                                 Dim cbBuff As Long, cCount As Long 
                                                 Dim p As Long, res As Long, i As Long 
    
                                                 'Setup the NETRESOURCE input structure. 
                                                 cbBuff = 10000 
                                                 cCount = &HFFFFFFFF 
    
                                                 'Open a Net enumeration operation handle: hEnum. 
    
                                                 res = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NR, hEnum) 
    
                                                 If res = 0 Then 
                                                 'Create a buffer large enough for the results. 
                                                 '100 00 bytes should be sufficient. 
                                                 lpBuff = GlobalAlloc(GPTR, cbBuff) 
                                                 'Call the enumeration function. 
                                                 res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff) 
                                                 If res = 0 Then 
                                                 p = lpBuff 
                                                 'WNetEnumResource fills the buffer with an array of 
                                                 'NETRESOURCE structures. Walk through the list and print 
                                                 'each remote name. 
                                                 For i = 1 To cCount 
                                                 CopyMemory NR, ByVal p, LenB(NR) 
                                                 Form1.List1.AddItem "Network Computer #" & i & " " & PointerToString(NR.lpRemoteName) 
                                                 p = p + LenB(NR) 
                                                 Next i 
                                                 End If 
                                                 If lpBuff <> 0 Then GlobalFree (lpBuff) 
                                                 WNetCloseEnum (hEnum) 'Close the enumeration 
                                                 Else 
                                                 End If 
                                                 End Sub 
    
    
                                                 'This is for form1 which has a list1 
    
                                                 Private Sub Form_Load() 
                                                 DoNetEnum 
    
                                                 End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width