Extracting Windows User/Login ID

TomB1974

New Member
Joined
Feb 16, 2004
Messages
1
I am building a db the requires me to keep track of activity by my users. Rather than create a users table I would like to extract the windows User/Login ID. I can write the code surounding the event I just need to retrieve the ID

TIA
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

anvil19

Board Regular
Joined
Nov 18, 2003
Messages
230
Hi TomB1974

This code will give you the user name and the machine name of the user :


Code:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
     (ByVal lpBuffer As String, nSize As Long) As Long
     
     Private Declare Function GetComputerName Lib "Kernel32" _
     Alias "GetComputerNameA" (ByVal lbbuffer As String, nSize As Long) As Long


Public Property Get ComputerName() As String
    Dim stBuff As String * 255, lAPIResult As Long
    Dim lBuffLen As Long

    lBuffLen = 255
    lAPIResult = GetComputerName(stBuff, lBuffLen)
    If lBuffLen > 0 Then ComputerName = Left(stBuff, lBuffLen)
End Property

Function SeeUser() As String

    Dim lpBuff As String * 25
    Dim ret As Long, UserName As String

    ret = GetUserName(lpBuff, 25)
    UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

SeeUser = UserName

End Function

Function SeeComputerName() As String
        SeeComputerName = ComputerName
End Function

Any Help??

anvil19
:eek:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,556
Messages
5,596,820
Members
414,104
Latest member
imamalidadashzada

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top