Article ID: 113688
Article Last Modified on 12/9/2003
96772 : INF: How to Use WNetGetUser() in Windows for Workgroups
' Enter each of the following Declare statements on one, single line:
Declare Function WNetGetUser Lib "wfwnet.drv" (ByVal szUser As String,
nBufferSize As Integer) As Integer
Declare Function MNetNetworkEnum Lib "wfwnet.drv"
(lphNetwork As Integer) As Integer
Declare Function MNetSetNextTarget Lib "wfwnet.drv"
(ByVal hNetwork As Integer) As Integer
' The following function determines the logged-in user in Windows for
' Workgroups:
Function MultiNetGetUser (UserName$) As Integer
Dim hNetDrv As Integer
Dim wRetEnum As Integer, ret As Integer
Dim wRetGetUser As Integer
Dim cb As Integer
Dim Found As Integer
Found = False
' Grab the 1st network:
hNetDrv = 0
wRetEnum = MNetNetworkEnum(hNetDrv)
' Loop while there are installed networks:
While (wRetEnum = 0) And Not Found
user$ = Space$(255)
cb = Len(user$)
' Make sure correct network is accessed in next WNetGetUser call:
ret = MNetSetNextTarget(hNetDrv)
' Get the user:
wRetGetUser = WNetGetUser(user$, cb)
' Check for success:
If wRetGetUser = 0 Then
' Just grab the relevant characters:
UserName$ = Left$(user$, cb - 1)
MsgBox UserName$, , "WNetGetUser"
Found = True
End If
' Get the next network:
wRetEnum = MNetNetworkEnum(hNetDrv)
Wend
If Not Found Then
MsgBox "WNetGetUser not supported on any of the Multinet subnets"
End If
MultiNetGetUser = Found
End Function
Sub Command1_Click()
r = MultiNetGetUser(UserName$)
End Sub
Additional query words: 2.00 3.00 3.10 3.11 username multi-net
Keywords: KB113688