Solved

Getting NT user id

Posted on 2000-03-19
7
164 Views
Last Modified: 2010-05-02
Hi,

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

Thanks
0
Comment
7 Comments
 
LVL 2

Expert Comment

by:johnny6
ID: 2633833
You can check-out http://www.netfokus.dk/vbadmincode/. Look under Windows NT. They have code which covers most NT Admin functions.

John
0
 
LVL 1

Expert Comment

by:pclement
ID: 2633838
Under NT, 2000, and 9x I believe the GetUserName API function call is sufficient:

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

0
 
LVL 4

Expert Comment

by:tmack
ID: 2633877
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 2

Expert Comment

by:brice123
ID: 2634988
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
 
LVL 12

Author Comment

by:Alfredo Luis Torres Serrano
ID: 2636480
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
 
LVL 1

Expert Comment

by:pclement
ID: 2637272
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
 
LVL 4

Accepted Solution

by:
tmack earned 10 total points
ID: 2638304
Just asign them to me...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

813 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

15 Experts available now in Live!

Get 1:1 Help Now