How to Use WNetGetUser() in Windows for Workgroups from VB 3.0Last reviewed: June 21, 1995Article ID: Q113688 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYThe information from this article is taken from the following Microsoft Knowledge Base article: ARTICLE-ID: Q96772 TITLE : INF: How to Use WNetGetUser() in Windows for WorkgroupsThe information is duplicated here to include sample code that is converted for use in Visual Basic. WNetGetUser() is documented on page 194 in the Microsoft Windows Device Driver Kit (DDK) "Device Driver Adaptation Guide" for version 3.1. This function can be used to retrieve the current user name of the user logged on to the network underlying Windows. However, when using this function in Microsoft Windows for Workgroups, WNetGetUser() returns WN_SUCCESS but the user name string is empty. Because WFWNET.DRV is a multinet driver, the network that supports WNetGetUser() must be activated before using this function.
MORE INFORMATIONUntil the release of the Windows for Workgroups Software Development Kit (SDK), the WNetGetUser() function was used internally by Windows. It is documented in the Windows version 3.1 "Device Driver Adaptation Guide" for network device driver developers. Now the Windows for Workgroups SDK allows you to call WNetGetUser() from an application. However, when using this function on a system with a multinet driver, you must activate the supporting network by first using MNetSetNextTarget(). If the target network has not been set, the function returns WN_SUCCESS but the returned string for the user name is empty. This is documented in the description of MNetSetNextTarget() in the Windows for Workgroups SDK. It is not sufficient to just call MNetSetNextTarget() before WNetGetUser(). The current target network may not support WNetGetUser(). To set the target network to use WNetGetUser() correctly, you must number the networks and call WNetGetUser() for each network. If WNetGetUser() does not return WN_SUCCESS, then increment the network number for the next target network and iterate the loop. If the loop iterates through all of the networks but WNetGetUser() never returns WN_SUCCESS, then none of the target networks support WNetGetUser(). The following sample code demonstrates how to do this.
Step-by-Step Example
|
Additional reference words: 2.00 3.00 3.10 3.11 username multi-net
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |