×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Get Windows User Name

Get Windows User Name

Get Windows User Name

(OP)
How can I get the actual Windows User-Name on a NT4.0 and WIN95 PC
in a Text variable ?
I need the User including the Domain-Name.

RE: Get Windows User Name

you have to use the win32 api to retrieve that info. Do you have any experience with the Windows API? If not I can recommend a book called Visual Basic 5.0 programmers guide to the Win32 API. You would need to set up a module with the getusername function. And call the function from your form with a button click event or other event of your choice. You can run the apiload.exe in your \devstudio\vb\winapi\ directory. This way you can view the necessaries of the getusername api. Need anymore clues post away...

pos

RE: Get Windows User Name

Try this declaration in the declarations sections of a module

Declare Function WNetGetUser Lib "advapi32.dll" Alias "GetUserNameA" (ByVal szUser$, lpnBufferSize%) As Long

and call it like this:

dim uname as string, len as integer
call GetUserNameA(uname,len)

uname should be set to the user name

Mike

RE: Get Windows User Name

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function ClipNull(InString As String) As String

Dim intpos As Integer

If Len(InString) Then
intpos = InStr(InString, vbNullChar)
If intpos > 0 Then
ClipNull = Left(InString, intpos - 1)
Else
ClipNull = InString
End If
End If

End Function
Function GetUser() As String

Dim lpUserID As String
Dim nBuffer As Long
Dim Ret As Long
lpUserID = String(25, 0)
nBuffer = 25
Ret = GetUserName(lpUserID, nBuffer)

If Ret Then
GetUser$ = lpUserID$
End If

End Function
'Call like this
dim strUser as string
strUser = ClipNull(GetUser())

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close