Solved

Getting NT user id

Posted on 2000-03-19
7
162 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Expert Comment

by:brice123
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Just asign them to me...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
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 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…

771 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