Solved

nt user

Posted on 2000-05-02
5
164 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 142

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i unlock a picture file that was loaded in a picturebox in visual c#? 4 93
Copy a row 12 61
Add a task in Outlook from access 11 39
Automatic Email Reminder 4 36
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…
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 …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

776 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