Network Help 
Author Message
 Network Help

Hi there,

This is my first time in here, so be kind :-)

I am using VB5, and I wish to get a list of all of the computers on my LAN, along the same line as Network Neighbourhood does when you open that, I only want the names though.

I know it can be done in DOS using net view, however is there a Windows95/NT solution.

Any help would be greatly appreciated.

--
Cheers

Ed
--
Ed Henderson



Mon, 12 Mar 2001 03:00:00 GMT  
 Network Help

Quote:
>Hi there,
>This is my first time in here, so be kind :-)
>I am using VB5, and I wish to get a list of all of the computers on my LAN,

along the same line as >Network Neighbourhood does when you open that, I
only want the names though.

Quote:
>I know it can be done in DOS using net view, however is there a

Windows95/NT solution.

You can use NetServerEnum and specify SV_TYPE_WORKSTATION, but I don't
recommend this for you since you are a beginner (no offense, but even I find
it somewhat difficult to call this function).

Try this instead:

Declare Function WNetOpenEnum Lib "mpr" Alias "WNetOpenEnumA" (ByVal dwScope
As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any,
lphEnum As Long) As Long
Declare Function WNetCloseEnum Lib "mpr.dll" Alias "WNetCloseEnum" (ByVal
hEnum As Long) As Long
Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA"
(ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As
Long) As Long
' lpBuffer is a pointer to an array of NETRESOURCE structures
Type NETRESOURCE
 dwScope As Long
 dwType As Long
 dwDisplayType As Long
 dwUsage As Long
 lpLocalName As String
 lpRemoteName As String
 lpComment As String
 lpProvider As String
End Type

Public Const RESOURCE_LOCALNET = &H2
Public Const NO_ERROR=&H0
Public Const RESOURCETYPE_DISK=&H1
Dim hEnum As Long, rc As Long, nr As NETRESOURCE
' start an enumeration process
rc=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK, ByVal 0&,hEnum)
If rc=NO_ERROR Then
 Do While rc=NO_ERROR
 ' continue the enumeration
  rc=WNetEnumResource(hEnum,-1,nr,LenB(nr)
    Debug.Print "Connected to: " & nr.lpRemoteName & " as " & nr.lpLocalName
 Loop
End If
' must close the enumeration handle
rc=WNetCloseEnum(hEnum)

Quote:
>Any help would be greatly appreciated.

BTW, it is generally not appropriate to post in HTML.
--
Damit Senanayake
Microsoft MVP - Visual Basic
ICQ#: 6930718


Tue, 13 Mar 2001 03:00:00 GMT  
 Network Help
I'm trying to enumerate through the network as well, so I tried your code.
No luck.  I get an "Invalid Outside Procedure" error when I try to run it.
The de{*filter*} highlights the first arguement of WNetOpenEnum,
"RESOURCE_GLOBALNET".

Any ideas?

Thanks,
Jason

Quote:
>Try this instead:

>Declare Function WNetOpenEnum Lib "mpr" Alias "WNetOpenEnumA" (ByVal
dwScope
>As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any,
>lphEnum As Long) As Long
>Declare Function WNetCloseEnum Lib "mpr.dll" Alias "WNetCloseEnum" (ByVal
>hEnum As Long) As Long
>Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA"
>(ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As
>Long) As Long
>' lpBuffer is a pointer to an array of NETRESOURCE structures
>Type NETRESOURCE
> dwScope As Long
> dwType As Long
> dwDisplayType As Long
> dwUsage As Long
> lpLocalName As String
> lpRemoteName As String
> lpComment As String
> lpProvider As String
>End Type

>Public Const RESOURCE_LOCALNET = &H2
>Public Const NO_ERROR=&H0
>Public Const RESOURCETYPE_DISK=&H1
>Dim hEnum As Long, rc As Long, nr As NETRESOURCE
>' start an enumeration process
>rc=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK, ByVal 0&,hEnum)
>If rc=NO_ERROR Then
> Do While rc=NO_ERROR
> ' continue the enumeration
>  rc=WNetEnumResource(hEnum,-1,nr,LenB(nr)
>    Debug.Print "Connected to: " & nr.lpRemoteName & " as " &
nr.lpLocalName
> Loop
>End If
>' must close the enumeration handle
>rc=WNetCloseEnum(hEnum)

>>Any help would be greatly appreciated.

>BTW, it is generally not appropriate to post in HTML.
>--
>Damit Senanayake
>Microsoft MVP - Visual Basic
>ICQ#: 6930718



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help

:I'm trying to enumerate through the network as well, so I tried your code.
:No luck.  I get an "Invalid Outside Procedure" error when I try to run it.
:The de{*filter*} highlights the first arguement of WNetOpenEnum,
:"RESOURCE_GLOBALNET".

Change the constant RESOURCE_LOCALNET to RESOURCE_GLOBALNET.

--
Damit Senanayake
Microsoft MVP - Visual Basic
ICQ#: 6930718



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help

Quote:
>Change the constant RESOURCE_LOCALNET to >RESOURCE_GLOBALNET.

Thanks, but still no dice.  I changed it both in the function call, and in
the const declaration.  I even looked up the contstant in API Viewer and
made sure it was correct.

I'm stumped.

Ahoy,
Jason



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help


:Thanks, but still no dice.  I changed it both in the function call, and in
:the const declaration.  I even looked up the contstant in API Viewer and
:made sure it was correct.
:
:I'm stumped.

This is what MSDN says on the matter:
[WNetOpenEnum:]

Parameters
dwScope

Specifies the scope of the enumeration. This parameter can be one of the
following values:
Value                                                              Meaning
RESOURCE_CONNECTED              All currently connected resources (the
dwUsage parameter is ignored).
RESOURCE_GLOBALNET              All resources on the network.
RESOURCE_REMEMBERED            All remembered (persistent) connections
(dwUsage is ignored).

dwType

Specifies the resource types to enumerate. This parameter can be a
combination of the following values: Value
Meaning

RESOURCETYPE_ANY  All resources (this value cannot be combined with
RESOURCETYPE_DISK or RESOURCETYPE_PRINT).

RESOURCETYPE_DISK                                                      All
disk resources.

RESOURCETYPE_PRINT                                                  All
print resources.

If a network provider cannot distinguish between print and disk resources,
it may enumerate all resources.

dwUsage

Specifies the resource usage to be enumerated. This parameter can be a
combination of the following values:
Value
Meaning

0
All resources

RESOURCEUSAGE_CONNECTABLE                                      All
connectable resources

RESOURCEUSAGE_CONTAINER                                          All
container resources

This parameter is ignored if the dwScope parameter is not
RESOURCE_GLOBALNET.

lpNetResource

Points to a NETRESOURCE structure specifying the container to enumerate.

If this parameter is NULL, the root of the network is assumed. Windows
organizes a network as a hierarchy; the root is the topmost container in the
network.

If this parameter is not NULL, it must point to a NETRESOURCE structure.
This structure can be filled in by the application or be returned by a call
to the WNetEnumResource function. The NETRESOURCE structure must specify a
container resource; that is, the RESOURCEUSAGE_CONTAINER value must be
specified in the dwUsage member.

To enumerate all network resources, an application can begin the enumeration
by calling WNetOpenEnum with lpNetResource set to NULL and then use the
returned handle with WNetEnumResource to enumerate resources. If one of the
resources in the NETRESOURCE array returned by the WNetEnumResource function
is a container resource, WNetOpenEnum can be used to open the resource for
further enumeration.

If the dwScope parameter is not RESOURCE_GLOBALNET, this parameter must be
NULL.

lphEnum

Points to a variable filled with an enumeration handle that can be used in a
subsequent call to WNetEnumResource.

--
Damit Senanayake
Microsoft MVP - Visual Basic
ICQ#: 6930718



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help
Hi Jason --

Quote:
>I'm trying to enumerate through the network as well, so I tried your code.
>No luck.  I get an "Invalid Outside Procedure" error when I try to run it.
>The de{*filter*} highlights the first arguement of WNetOpenEnum,
>"RESOURCE_GLOBALNET".

>Any ideas?

Yeah.  As is typical with your correspondent, he didn't provide functional code, nor
note why it wouldn't work as is.  (Amazingly, he doesn't even seem to understand
himself!)  The error you're getting is because the snippet offered needs to be placed
within a procedure.

But that's just the beginning.  That offering was *so* sloppy that many other errors
wait in hiding.  For instance, Damit didn't even use the correct number of parameters
to the WNetOpenEnum call.  He also begs for GPFs by using constants in the
WNetEnumResource call where variables are required (they may be written to!).  In
fact, the whole post appeared to have not been thought out whatsoever.  Were I to
guess, Damit was out and out guessing himself, and has never even tried to make these
calls.

Below is the code from a functional module.  I'm sure it's ripe for optimization, but
hey, "working *is* a feature", eh? <g>

Enjoy...   Karl

' ============== BOF: MNetEnum.bas ==============
Option Explicit

Private Declare Function WNetOpenEnum Lib "mpr" Alias "WNetOpenEnumA" (ByVal dwScope
As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum
As Long) As Long
Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA"
(ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As Long) As
Long

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any,
lpString2 As Any) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (lpString As Any) As
Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any,
Source As Any, ByVal Length As Long)

Private 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
'   lpLocalName As String
'   lpRemoteName As String
'   lpComment As String
'   lpProvider As String
End Type

Private Const RESOURCE_CONNECTED = &H1
Private Const RESOURCE_GLOBALNET = &H2
Private Const RESOURCE_REMEMBERED = &H3

Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_UNKNOWN = &HFFFF

Private Const RESOURCEUSAGE_CONNECTABLE = &H1
Private Const RESOURCEUSAGE_CONTAINER = &H2
Private Const RESOURCEUSAGE_RESERVED = &H80000000

Private Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Private Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Private Const RESOURCEDISPLAYTYPE_SERVER = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE = &H3
Private Const RESOURCEDISPLAYTYPE_FILE = &H4
Private Const RESOURCEDISPLAYTYPE_GROUP = &H5

Private Const NO_ERROR = &H0

Private Const Indent = 2

Public Sub NetEnum()
   Dim hEnum As Long
   Dim rc As Long
   Dim cnt As Long
   Dim nr As NETRESOURCE
   Dim b() As Byte
   Dim buflen As Long

   ' start an enumeration process...
   rc = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_CONTAINER,
ByVal 0&, hEnum)
   If rc = NO_ERROR Then
      buflen = 1024
      ReDim b(0 To buflen - 1) As Byte
      ' get network root
      Do
         cnt = 1
         rc = WNetEnumResource(hEnum, cnt, b(0), buflen)
         ' if we have a container, enumerate it...
         If rc = NO_ERROR Then
            CopyMem nr, b(0), Len(nr)
            Debug.Print PointerToStringA(nr.lpRemoteName)
            If (nr.dwUsage And RESOURCEUSAGE_CONTAINER) Then
               Call EnumContainers(nr, 1)
            End If
         Else
            Exit Do
         End If
      Loop
   End If
   ' must close the enumeration handle
   rc = WNetCloseEnum(hEnum)
End Sub

Public Sub EnumContainers(cntr As NETRESOURCE, ByVal Level As Long)
   Dim hEnum As Long
   Dim rc As Long
   Dim cnt As Long
   Dim nr As NETRESOURCE
   Dim b() As Byte
   Dim buflen As Long

   ' start an enumeration process
   rc = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_CONTAINER,
cntr, hEnum)
   If rc = NO_ERROR Then
      buflen = 1024
      ReDim b(0 To buflen - 1) As Byte
      ' continue the enumeration
      Do
         cnt = 1
         rc = WNetEnumResource(hEnum, cnt, b(0), buflen)
         If rc = NO_ERROR Then
            CopyMem nr, b(0), Len(nr)
            Debug.Print Space(Indent * Level);
            Debug.Print PointerToStringA(nr.lpRemoteName)
            If (nr.dwUsage And RESOURCEUSAGE_CONTAINER) Then
               Call EnumContainers(nr, Level + 1)
               Call EnumConnections(nr, Level + 1)
            End If
         Else
            Exit Do
         End If
      Loop
   End If
   ' must close the enumeration handle
   rc = WNetCloseEnum(hEnum)
End Sub

Public Sub EnumConnections(cntr As NETRESOURCE, ByVal Level As Long)
   Dim hEnum As Long
   Dim rc As Long
   Dim cnt As Long
   Dim nr As NETRESOURCE
   Dim b() As Byte
   Dim buflen As Long

   ' start an enumeration process
   rc = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_CONNECTABLE,
cntr, hEnum)
   If rc = NO_ERROR Then
      buflen = 1024
      ReDim b(0 To buflen - 1) As Byte
      ' continue the enumeration
      Do
         cnt = 1
         rc = WNetEnumResource(hEnum, cnt, b(0), buflen)
         If rc = NO_ERROR Then
            CopyMem nr, b(0), Len(nr)
            Debug.Print Space(Indent * Level);
            Debug.Print PointerToStringA(nr.lpRemoteName)
         Else
            Exit Do
         End If
      Loop
   End If
   ' must close the enumeration handle
   rc = WNetCloseEnum(hEnum)
End Sub

Private Function PointerToStringA(lpStringA As Long) As String
   Dim Buffer() As Byte
   Dim nLen As Long

   If lpStringA Then
      nLen = lstrlen(ByVal lpStringA)
      If nLen Then
         ReDim Buffer(0 To (nLen - 1)) As Byte
         CopyMem Buffer(0), ByVal lpStringA, nLen
         PointerToStringA = StrConv(Buffer, vbUnicode)
      End If
   End If
End Function
' ============== EOF: MNetEnum.bas ==============



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help
Damit --

That's the *lamest* damn post I've seen in quite some time!  You've never made these
calls yourself, have you?  In fact, you're GUESSING what might work, right?

Later...   Karl
--
[This space intentionally left blank.]


Quote:


>>Hi there,

>>This is my first time in here, so be kind :-)

>>I am using VB5, and I wish to get a list of all of the computers on my LAN,
>along the same line as >Network Neighbourhood does when you open that, I
>only want the names though.

>>I know it can be done in DOS using net view, however is there a
>Windows95/NT solution.

>You can use NetServerEnum and specify SV_TYPE_WORKSTATION, but I don't
>recommend this for you since you are a beginner (no offense, but even I find
>it somewhat difficult to call this function).

>Try this instead:

>Declare Function WNetOpenEnum Lib "mpr" Alias "WNetOpenEnumA" (ByVal dwScope
>As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any,
>lphEnum As Long) As Long
>Declare Function WNetCloseEnum Lib "mpr.dll" Alias "WNetCloseEnum" (ByVal
>hEnum As Long) As Long
>Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA"
>(ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As
>Long) As Long
>' lpBuffer is a pointer to an array of NETRESOURCE structures
>Type NETRESOURCE
> dwScope As Long
> dwType As Long
> dwDisplayType As Long
> dwUsage As Long
> lpLocalName As String
> lpRemoteName As String
> lpComment As String
> lpProvider As String
>End Type

>Public Const RESOURCE_LOCALNET = &H2
>Public Const NO_ERROR=&H0
>Public Const RESOURCETYPE_DISK=&H1
>Dim hEnum As Long, rc As Long, nr As NETRESOURCE
>' start an enumeration process
>rc=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK, ByVal 0&,hEnum)
>If rc=NO_ERROR Then
> Do While rc=NO_ERROR
> ' continue the enumeration
>  rc=WNetEnumResource(hEnum,-1,nr,LenB(nr)
>    Debug.Print "Connected to: " & nr.lpRemoteName & " as " & nr.lpLocalName
> Loop
>End If
>' must close the enumeration handle
>rc=WNetCloseEnum(hEnum)

>>Any help would be greatly appreciated.

>BTW, it is generally not appropriate to post in HTML.
>--
>Damit Senanayake
>Microsoft MVP - Visual Basic
>ICQ#: 6930718



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help

Quote:



>:Thanks, but still no dice.  I changed it both in the function call, and in
>:the const declaration.  I even looked up the contstant in API Viewer and
>:made sure it was correct.
>:
>:I'm stumped.

>This is what MSDN says on the matter:

Why don't you just stop the bullshit, and admit that you're as stumped as your
correspondent.  You're not helping, only hurting.  Grow up.

Later...   Karl



Sun, 18 Mar 2001 03:00:00 GMT  
 Network Help
Thanks for all the *clean* code that actually might work!

I'm going to give it a try this weekend.

Thanks again!

Ahoy,
Jason



Tue, 20 Mar 2001 03:00:00 GMT  
 Network Help
Thanks for all the *clean* code that actually might work!

I'm going to give it a try this weekend.

Thanks again!

Ahoy,
Jason



Tue, 20 Mar 2001 03:00:00 GMT  
 Network Help
I think it only works on NT also.

are you using NT??

Eric Davis

Quote:




>>:Thanks, but still no dice.  I changed it both in the function call, and
in
>>:the const declaration.  I even looked up the contstant in API Viewer and
>>:made sure it was correct.
>>:
>>:I'm stumped.

>>This is what MSDN says on the matter:

>Why don't you just stop the bullshit, and admit that you're as stumped as
your
>correspondent.  You're not helping, only hurting.  Grow up.

>Later...   Karl



Sat, 24 Mar 2001 03:00:00 GMT  
 Network Help
Hi Eric --

Quote:
>I think it only works on NT also.

No, the WNetXXX functions pretty much work on both platforms.  The NetXXX functions
may be what you're thinking about?

Quote:
>are you using NT??

But, of course!  What else is there?  :-)

Later...   Karl



Sat, 24 Mar 2001 03:00:00 GMT  
 Network Help
Hi Eric / All --

Quote:

>>[Damit] just stop the bullsh*t, and admit that you're as stumped as your
>>correspondent.  You're not helping, only hurting.  Grow up.

Ouch!  Did I really say that?  Here?  Please, "Pardon my French." <g>

Sorry...   Karl



Sat, 24 Mar 2001 03:00:00 GMT  
 Network Help
Karl,

    Oops,!!

Karl please can you help me .  I am trying to find out how to do the
following things
create a directory on a server
set file level permissions
share the directory
set permissions to the share.

can you please help me.

I know the APIs that I need to use but I have no Idea how to use them.


Quote:
>Hi Eric --

>>I think it only works on NT also.

>No, the WNetXXX functions pretty much work on both platforms.  The NetXXX
functions
>may be what you're thinking about?

>>are you using NT??

>But, of course!  What else is there?  :-)

>Later...   Karl



Sat, 24 Mar 2001 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Dial Up Networking Help

2. *****NETWORK HELP*******

3. Need network help

4. local network help

5. Using VB to LOGIN to a network (HELP!)

6. Network Help

7. Need application Dev for Network help

8. Dial-Up Network Help

9. VB IPX Networking help?

10. VB 4 on a Novell Network -- Help

11. ***NETWORK HELP*****

12. Network Help

 

 
Powered by phpBB® Forum Software