Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

nt user

Posted on 2000-05-02
5
Medium Priority
?
173 Views
Last Modified: 2010-05-02
Is there a function that will get the current user of the domain.
All users are part of a NT domain therefor they are valid users.
I need to get there NT login name.
Any ideas?
0
Comment
Question by:chicabow
5 Comments
 
LVL 1

Expert Comment

by:pauljk
ID: 2771822
Try this...  Reject me if it doesn't work...

It's an API call...

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




Dim s$,cnt&,dl&
cnt&=199
s$=String$(200,0)
dl&=GetUserName(s$,cnt)
Debug.Print Left$(s$,cnt);cnt
0
 
LVL 2

Expert Comment

by:Veroland
ID: 2771964
The api youre looking for is called
Public Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 75 total points
ID: 2771971
You can easily retrieve a user's network logon name by using the following API call:

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


To retrieve a "clean" version of the name, use this function:

Public Function NTDomainUserName() As String
Dim strBuffer As String * 255
Dim lngBufferLength As Long
Dim lngRet As Long
Dim strTemp As String

    lngBufferLength = 255
    lngRet = GetUserName(strBuffer, lngBufferLength)
    strTemp = UCase(Trim$(strBuffer))
    NTDomainUserName = Left$(strTemp, Len(strTemp) - 1)

End Function

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2772288
Much easier:
try Environ("USERNAME") and
Environ("USERDOMAIN")
0
 
LVL 1

Author Comment

by:chicabow
ID: 2818757
This is the only one that worked with ease..

angelIII
Did not work...at all...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

926 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