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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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:
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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
Back
Top