Get User name from NT WorkSt. 4.0

Using Access97/VBA5 with or without Access security activated, I need (programmatically)the Logon name of each user for a Peek-to-Peer NTWorkStation 4.0 configuation with up to 10 users. The object is to save the user from logging on twice, once to NT and again to Access.
mrlAsked:
Who is Participating?
 
twardConnect With a Mentor Commented:
The GetUserName API call should be able to get the Logon Name for Windows 95/NT:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.
BOOL GetUserName(
    LPTSTR lpBuffer,      // address of name buffer
    LPDWORD nSize       // address of size of name buffer
   );      
 
Parameters
lpBuffer
Points to the buffer to receive the null-terminated string containing the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails.
nSize
Pointer to a DWORD that, on input, specifies the maximum size, in characters, of the buffer specified by the lpBuffer parameter. If this buffer is not large enough to contain the entire user name, the function fails. If the function succeeds, it will place the number of characters copied to the buffer into the DWORD that nSize points to.
 
Return Values
If the function succeeds, the return value is TRUE, and the variable pointed to by nSize contains the number of characters copied to the buffer specified by lpBuffer, including the terminating null character.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If the current thread is impersonating another client, the GetUserName function returns the user name of the client that the thread is impersonating.

0
 
mrlAuthor Commented:
Edited text of question
0
 
mrlAuthor Commented:
Edited text of question
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
mrlAuthor Commented:
I am an experienced programmer but inexperienced with Win API so please be tutorial in your response. I have no references to NT API documentation so hints as to how to use the recommended functions will be necessary. Thank you in advance. MRL
Email is malc@ddtcom.com
0
 
mrlAuthor Commented:
Whow! I hadn't even finished typing my comments and there was an answer!!!! This forem is fantastic. This is probably a commonly asked question although I did not see it in the PAQ list.  I need a few minutes to review the answer to see if I understand.
Thank you.
0
 
twardCommented:
I do think I have answered this one before, but I hate going through the PAQ unless there is a search through them that I have missed.

Just in case here is an example of using it within VB:

Dim Size As Long
Dim UserName As String
 
Size = 255

UserName = String(Size, 0)

Call GetUserName(UserName, Size)

UserName = Trim(Left(UserName, Size - 1))
0
 
mrlAuthor Commented:
To tward:
Have read your answer and have lots of techical questions about how I use the parameters in the call with Access/VBA5.0. I will consult the language references to see how I can get these values in and out  of this language. i.e., how do I define the lpbuffer, nsize etc or is it as simple as
Dim lpbuffer long
Dim nSize double
etc???
0
 
mrlAuthor Commented:
tward:
Once again your answer preceded my question...Are you clarvoyant or just a genius? Please Stand by while I look at your answer.
0
 
mrlAuthor Commented:
tward:
As I said, I haven't used API calls before so I'm unclear as to the exact way I declare the function in VB but this is obviously an exercise for the student. I will release this (or do whatever I have to do...this is my very first visit to this site) so you receive your appropriate reward. Thank you so much for such timely information. MRL
0
 
mrlAuthor Commented:
Anyone reading this thread should understand the time element involved...the answer from the expert arrived on my screen before appended my first comment and susequent clarifications followed just as rapidly...this is the greatest site I have ever found on the net!!! Experts site is not misnamed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.