Microsoft KB Archive/112013

From BetaArchive Wiki

Microsoft Knowledge Base

How to Get List of Network Connections with WNetGetConnection

Last reviewed: October 19, 1994
Article ID: Q112013

The information in this article applies to:

- Microsoft Test for Windows, version 2.0

SUMMARY

This article shows by example how to print a list of all the active network connections on drives A-Z. The example makes a call to the Windows API WNetGetConnection() function.

MORE INFORMATION

The WNetGetConnection() function returns the name of the network resource associated with the specified redirected local device.

UINT WNetGetConnection(lpszLocalName, lpszRemoteName, cbRemoteName)

Parameter           Description
lpszLocalName       Points to a null-terminated string specifying the
                    name of the redirected local device.
lpszRemoteName      Points to the buffer to receive the null-
                    terminated name of the remote network resource.
cbRemoteName        Points to a variable specifying the maximum number
                    of bytes the buffer pointed to by lpszRemoteName
                    can hold. The function sets this variable to the
                    number of bytes copied to the buffer.

Step-by-Step Example

  1. Start TESTDRVR or from the File menu, choose New (Alt, F, N)
  2. Type the following in the script window:

       ' $include 'declares.inc'
       viewport clear
       ' Dimension pointer variable:
       dim lyle as pointer to integer
    
       maxlen% = 64
       ' Initialize variables to be passed to the function:
       y$ = space$(maxlen%)
       lyle = varptr(maxlen%)
       ' Loop through characters with ASCII values 68 to 90:
       for  i = 68 to 90
          x$ = chr$(i)+ ":"
          ret= wnetgetconnection(x$, y$,lyle)
          ' If ret value is 0, print what was returned:
          if ret = 0 then Print ret, y$
       next
    
  3. Run the script. The information returned by the program will be printed out in the Viewport window.

Additional reference words: 2.00

KBCategory: kbtool kbprg
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 19, 1994
©1997 Microsoft Corporation. All rights reserved. Legal Notices.