Connecting Tech Pros Worldwide Forums | Help | Site Map

Windows Login Name

John
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi

How can I get the currently logged in username from windows 2000/xp?

Thanks

Regards







Allen Browne
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Windows Login Name


"John" <John@nospam.infovis.co.uk> wrote in message
news:4076ca75$0$232$cc9e4d1f@news.dial.pipex.com.. .[color=blue]
> How can I get the currently logged in username from windows 2000/xp?[/color]

It is an API call. See:
http://www.mvps.org/access/api/api0008.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


(Pete Cresswell)
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Windows Login Name


RE/[color=blue]
>How can I get the currently logged in username from windows 2000/xp?[/color]

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


Public Function userIdWindowsGet() As String
debugStackPush mModuleName & ": userIdWindowsGet"
On Error GoTo userIdWindowsGet_err

' PURPOSE: To retrieve the Windows UserID of the person currently logged on to
this PC
' RETURNS: UseID or empty string

Dim myBuffer As String * 255
Dim myUserName As String

GetUserName myBuffer, Len(myBuffer) 'Get the
user name
myUserName = Left(Trim(myBuffer), InStr(myBuffer, Chr(0)) - 1) 'Trim excess
characters

If Len(myUserName) > 0 Then
userIdWindowsGet = myUserName
Else
bugAlert True, "Unable to get Windows UserID"
End If

userIdWindowsGet_xit:
debugStackPop
On Error Resume Next
Exit Function

userIdWindowsGet_err:
bugAlert True, ""
Resume userIdWindowsGet_xit
End Function
-------------------------------------
--
PeteCresswell
Closed Thread