Solved

Getting NT user id

Posted on 2000-03-19
7
165 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

830 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