Solved

nt user

Posted on 2000-05-02
5
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
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]
Comment Utility
Much easier:
try Environ("USERNAME") and
Environ("USERDOMAIN")
0
 
LVL 1

Author Comment

by:chicabow
Comment Utility
This is the only one that worked with ease..

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now