Solved

nt user

Posted on 2000-05-02
5
165 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 25 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: 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 (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

679 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