Usage or Error Logging using Citrix (1 Viewer)

Rx_

Nothing In Moderation
Local time
Today, 00:46
Joined
Oct 22, 2009
Messages
2,803
This may apply to Terminal server as well:
this might save someone else some embarrasement from my lesson learned. :(
Environ("username") ' NOT CurrentUser() current user always displayed "admin" in Citrix environment

Set up a usage log, then had a contest with a prize for users to "test the beta program" Got my wish, but every user was "admin" in the Citrix environment. Thousands of clicks.

For Citrix, best to use a split database.
With MZ tools, use a hot key to insert a call to LogUsage function.

Code:
Option Compare Database
Option Explicit
'-----------------------------------------------------------------
' Procedure : LogUsage
' Author    : Rx
' Date      : 3/23/2010
' Purpose   : Logs user activity to table
'-------------------------------------------------------------------
'
Function LogUsage(ByVal strFormName As String, _
    strCallingProc As String, Optional ControlName) As Boolean
10       On Error GoTo Err_LogUsage
          Dim rst As DAO.Recordset  ' The tLogUsage table
20            Set rst = CurrentDb.OpenRecordset("tLogUsage", , dbAppendOnly)
30                rst.AddNew
40                rst![UseDate] = Now()
50                rst![strFormName] = strCallingProc
60                rst![CallingProc] = strCallingProc
70                rst![UserName] = Environ("username")  ' CurrentUser()  current user does not show up in Citrix
80                If Not IsMissing(ControlName) Then
90                    rst![ControlName] = Left(ControlName, 75)
100               End If
110           rst.Update
120           rst.Close
130           LogUsage = True
Exit_LogUsage:
140       Set rst = Nothing
150       Exit Function
Err_LogUsage:
          ' just resume next and the usage is not logged
160       Err.Clear
170       Resume Exit_LogUsage
End Function
 

HiTechCoach

Well-known member
Local time
Today, 01:46
Joined
Mar 6, 2006
Messages
4,357
This may apply to Terminal server as well:
this might save someone else some embarrasement from my lesson learned. :(
Environ("username") ' NOT CurrentUser() current user always displayed "admin" in Citrix environment

Set up a usage log, then had a contest with a prize for users to "test the beta program" Got my wish, but every user was "admin" in the Citrix environment. Thousands of clicks.

For Citrix, best to use a split database.
With MZ tools, use a hot key to insert a call to LogUsage function.

Code:
Option Compare Database
Option Explicit
'-----------------------------------------------------------------
' Procedure : LogUsage
' Author    : Rx
' Date      : 3/23/2010
' Purpose   : Logs user activity to table
'-------------------------------------------------------------------
'
Function LogUsage(ByVal strFormName As String, _
    strCallingProc As String, Optional ControlName) As Boolean
10       On Error GoTo Err_LogUsage
          Dim rst As DAO.Recordset  ' The tLogUsage table
20            Set rst = CurrentDb.OpenRecordset("tLogUsage", , dbAppendOnly)
30                rst.AddNew
40                rst![UseDate] = Now()
50                rst![strFormName] = strCallingProc
60                rst![CallingProc] = strCallingProc
70                rst![UserName] = Environ("username")  ' CurrentUser()  current user does not show up in Citrix
80                If Not IsMissing(ControlName) Then
90                    rst![ControlName] = Left(ControlName, 75)
100               End If
110           rst.Update
120           rst.Close
130           LogUsage = True
Exit_LogUsage:
140       Set rst = Nothing
150       Exit Function
Err_LogUsage:
          ' just resume next and the usage is not logged
160       Err.Clear
170       Resume Exit_LogUsage
End Function

With JET 3.x and JET 4.x you are always using the built in Access Security. Access uses the default system.mdw work group file that is installed with Access. If you do nothing to change anything for the default system.mdw work group file setting than every use logs on with the default user admin.

This is true for every Access install. It is not limited to Citrx or Terminal Server.

To get he current user form the Access Work Group file that is current log into Access, the use the built in Access function CurrentUser().


As you have pointed out, you can cehck the Environ variable to get the current set value that is assume to the the currently logged on user by using:

Code:
Environ("username")

NOTE: This is not read-only data. It can easily be changed.

the DOS command to change it is this:

Code:
c:\> set username=fakename


I would urge you to use a Windows API call to get the actual user logged on.

Here is VBA code that will alwas retun the tru logg on user:

Code:
Option Compare Database
Option Explicit

'=========================================================================
' retrieve the network user name by accessing the API apiGetUserName.
'=========================================================================

Private Declare Function apiGetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
'=========================================================================
' retrieve the network computer name by accessing the API apiGetComputerName.
'=========================================================================

Private Declare Function apiGetComputerName Lib "kernel32" _
    Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

'=========================================================================
' This code is used to assign variables to the user information and hold it in memory
' so that it can be used as the user navigates through the database
'=========================================================================

Public Type CurrentUserInfo
    memName As String
    memLogInName As String
    memUserAccessLevel As Integer
    memTimeIn As String
End Type

Public CurrentDBUser As CurrentUserInfo
Function fOSUserName() As String
On Error GoTo fOSUserName_Err

    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
        
    If lngX <> 0 Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = ""
    End If
    
  
fOSUserName_Exit:
  Exit Function
  
fOSUserName_Err:
  MsgBox Error$
  Resume fOSUserName_Exit
End Function

Function fOSMachineName() As String
    'Returns the computername
    Dim lngLen As Long, lngX As Long
    Dim strCompName As String
        lngLen = 16
        strCompName = String$(lngLen, 0)
        lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
        fOSMachineName = Left$(strCompName, lngLen)
    Else
        fOSMachineName = ""
    End If
End Function
 

Users who are viewing this thread

Top Bottom