Microsoft KB Archive/112013

= 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
 Start TESTDRVR or from the File menu, choose New (Alt, F, N)  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  Run the script. The information returned by the program will be printed out in the Viewport window.