|
-
Sep 3rd, 2001, 06:12 PM
#1
Thread Starter
New Member
Current User???
I would like to know the code to show the current user logged in on a Win2000 and NT4 machine.
thanx,
gageseven
Last edited by gageseven; Sep 3rd, 2001 at 06:16 PM.
-
Sep 3rd, 2001, 06:37 PM
#2
PowerPoster
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
-
Sep 3rd, 2001, 06:54 PM
#3
Thread Starter
New Member
Thanks a bunch - works perfect
-
Sep 4th, 2001, 08:57 AM
#4
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.
-
Sep 4th, 2001, 09:40 AM
#5
Fanatic Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|