i have an app that runs as a service and under the system account and i need it to get the current logged in user, if a user is logged in, but with the following code all i get is the system account. any way to get the actual logged in user if there is a logged in user?
Code:Private Declare Function GetUserName Lib "advapi32" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Private Function GetThreadUserName() As String 'Retrieves the user name of the current 'thread. This is the name of the user 'currently logged onto the system. If 'the current thread is impersonating 'another client, GetUserName returns 'the user name of the client that the 'thread is impersonating. Dim buff As String Dim nSize As Long buff = Space$(MAX_USERNAME) nSize = Len(buff) If GetUserName(buff, nSize) = 1 Then GetThreadUserName = TrimNull(buff) Exit Function End If End Function


Reply With Quote