VB and VBA Users Source Code: Obtaining the current user name
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Obtaining the current user name
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Saturday, January 13, 2001
Hits:
858
Category:
Windows API
Article:
The following routine returns the name of the current user's login name: Option Explicit Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Purpose : Returns the name of the current user's logon name 'Inputs : N/A 'Outputs : The current username 'Author : Andrew Baker 'Date : 13/01/2001 21:00 'Notes : 'Revisions : As an alternative, can use Environ$("UserName") on NT/2000 Function UserName() As String Dim lLenUserName As Long Static ssUserName As String If Len(ssUserName) = 0 Then lLenUserName = 100 ssUserName = String$(lLenUserName, Chr$(0)) 'Get the username GetUserName ssUserName, lLenUserName 'strip the rest of the buffer ssUserName = Left$(ssUserName, lLenUserName - 1) End If UserName = ssUserName End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder