Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more


Get User name from  NT WorkSt. 4.0

Posted on 1998-06-16
Medium Priority
Last Modified: 2010-05-03
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.
Question by:mrl
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 2

Author Comment

ID: 1463445
Edited text of question

Author Comment

ID: 1463446
Edited text of question

Accepted Solution

tward earned 600 total points
ID: 1463447
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
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.
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.
If the current thread is impersonating another client, the GetUserName function returns the user name of the client that the thread is impersonating.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 1463448
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

Author Comment

ID: 1463449
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.

Expert Comment

ID: 1463450
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))

Author Comment

ID: 1463451
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

Author Comment

ID: 1463452
Once again your answer preceded my question...Are you clarvoyant or just a genius? Please Stand by while I look at your answer.

Author Comment

ID: 1463453
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

Author Comment

ID: 1463454
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.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question