I would like to know the code to show the current user logged in on a Win2000 and NT4 machine.
thanx,
gageseven
Printable View
I would like to know the code to show the current user logged in on a Win2000 and NT4 machine.
thanx,
gageseven
Like this:VB Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Form_Load() Dim strUserName As String 'Create a buffer strUserName = String(100, Chr$(0)) 'Get the username GetUserName strUserName, 100 'strip the rest of the buffer strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1) 'Show the username MsgBox "Hello " + strUserName End Sub
Thanks a bunch - works perfect
In addition to the user name, you can take the exact same code that chrisjk sent, replace GetUserName with GetComputerName
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
and get the machine name as well.
Or you could just use...
VB Code:
MsgBox Environ("UserDomain") & " " & Environ("UserName") & " " & Environ("ComputerName")
For further info on Environ functions see DreamWeaver's post at http://forums.vb-world.net/showthrea...157#post467157