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.

Jobs

How To

Get user name from Windows 2000 by randysmid
Posted: 27 Nov 02

If not already done so, create a new module in the Modules section.

Paste this statement into the General Declarations section of the module:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

  
Paste this code:

Function fWin2KUserName() As String
    Dim lngLength As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLength = 255
    lngX = apiGetUserName(strUserName, lngLength)
    If lngX <> 0 Then
        fWin2KUserName = Left$(strUserName, lngLength - 1)
    Else
        fWin2KUserName = "unknown"
    End If
End Function

You can run this function (fWin2KUserName) from anywhere within your application.  The best way is to set some variable to be equal to the function:
    Dim strUser as String
    strUser = fWin2KUserName


Questions?   rsmith@cta.org



Back to Microsoft: Access Modules (VBA Coding) FAQ Index
Back to Microsoft: Access Modules (VBA Coding) Forum

My Archive

Resources

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