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

Get User name from  NT WorkSt. 4.0

Posted on 1998-06-16
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
  • 8
  • 2

Author Comment

ID: 1463445
Edited text of question

Author Comment

ID: 1463446
Edited text of question

Accepted Solution

tward earned 150 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.

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


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 malc@ddtcom.com

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

839 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