From: cchubb@ida.org (Chris Chubb)
Subject: Getting the UserID from the network.
Date: 27 Apr 1995 14:38:34 GMT
Organization: IDA (Alexandria, VA)

Some people asked about getting the user name from the network.

Here goes:

Two functions, one for the regular API, and wone
for the Win32 api. I use the regular version:
Declare it from USER.EXE.
   ' Enter each of the following Declare statements on one, single line:
   Declare Function WNetGetUser Lib "USER" (ByVal szUser As String,
      nBufferSize As Integer) As Integer

If you are using WFW, use
   Declare Function WNetGetUser Lib "WFWNET.DRV" (ByVal szUser As String,
      nBufferSize As Integer) As Integer


Here is the C declaration:

WORD WNetGetUser(szUser, nBufferSize)
LPSTR szUser;	// buffer to receive name of user
WORD FAR * nBufferSize;	// size of buffer, in bytes
The WNetGetUser function retrieves the current user name. 
Parameters
szUser Points to the buffer to receive the current user name. 
nBufferSize Points to a variable containing the size of the buffer 
	pointed to by the szUser parameter. The function copies the 
	actual size, in bytes, of the user name to the variable.
 
Return Values
The return value is WN_SUCCESS if the function is successful; 
otherwise, it is one of the following error values:
Value	Meaning
(Note: I dont know the number values for these.)

WN_BAD_POINTER	The pointer is invalid.
WN_BAD_USER	The user is not logged in; there is no current user name. 
WN_MORE_DATA	The buffer was too small. The function copies the size, 
	in bytes, of the buffer required to hold the complete user name. 
WN_NET_ERROR	A network error occurred.
WN_NOT_SUPPORTED	This function is not supported. 
WN_OUT_OF_MEMORY	The function could not allocate sufficient 
	memory to complete its operation.


Some fo the constants that I found were:
   
-----------------------------------------------------------------------
   WN_SUCCESS             (&H0)        Function was successful.
   WN_NOT_SUPPORTED       (&H1)        Function was not supported.
   WN_OUT_OF_MEMORY       (&HB)        System was out of memory.
   WN_NET_ERROR           (&H2)        An error occurred on the network.
   WN_BAD_POINTER         (&H4)        Pointer was invalid.
   WN_BAD_NETNAME         (&H32)       Network resource name was invalid.
   WN_BAD_LOCALNAME       (&H33)       Local device name was invalid.
   WN_BAD_PASSWORD        (&H6)        Password was invalid.
   WN_ACCESS_DENIED       (&H7)        A security violation occurred.
   WN_ALREADY_CONNECTED   (&H34)       Local device was already connected

My compliments to the MS Developers Network CD, the BEST
FRIEND of Windose programmers everywhere. A bargain at twice the price!


-- 
Chris Chubb -- cchubb@ida.org (Alexandria, VA)
** Leading a life of noisy desperation. **
My opinions and $0.75 will get you a cup of coffee.

