Getting NT user id

Hi,

  How can i get the nt user id on VB 5?

Thanks
LVL 12
Alfredo Luis Torres SerranoDevelopment Director / DBAAsked:
Who is Participating?
 
tmackCommented:
Just asign them to me...
0
 
johnny6Commented:
You can check-out http://www.netfokus.dk/vbadmincode/. Look under Windows NT. They have code which covers most NT Admin functions.

John
0
 
pclementCommented:
Under NT, 2000, and 9x I believe the GetUserName API function call is sufficient:

http://home.earthlink.net/~butlerbob/vb/network/username.htm

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
tmackCommented:
Heres the code that you need to get the log in name. You will need to modify it to suit your needs.
Let me know if you need futrther assitants.

T




'Call Windows API
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long


Public Sub Buffer_Set()
sBuffer = Space$(255)                                   'Buffer for the name
lSize = Len(sBuffer)                                    'Actual size if the name
Call GetUserName(sBuffer, lSize)                        'Get the name from system
End Sub

 Call Buffer_Set                                         'Go and get the user name
    txtUSER.Text = Left$(sBuffer, lSize)              'Display user
0
 
brice123Commented:
While you can use many different API function to get user and domain information, if you're running under Windows NT or 2000 Server there is a shortest path, based on the fact that the operating system loads many piece of data into environment variables:

' this code works only under Windows NT and Windows 2000 Server
Debug.Print "Computer Name: " & Environ$("COMPUTERNAME")
Debug.Print "Logon Server: " & Environ$("LOGONSERVER")
Debug.Print "User Domain: " & Environ$("USERNAME")
Debug.Print "User Name: " & Environ$("USERNAME")

0
 
Alfredo Luis Torres SerranoDevelopment Director / DBAAuthor Commented:
Your answer does not work for me, thanks anyway.

tmack: please let me know how can i give the points to you, i have solved the problem with you answer.

Thanks a lot
0
 
pclementCommented:
Masteraco:

Just an FYI, the answer tmack posted was the same as mine although posted several minutes later. Just to verify, did my code example reference not work for you?

If the code is bad I would like to know so that I can correct the source. Thanks.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.