Skip to Content

How to get the end user name in Thin Client.

Estimated Reading Time: 1 Minutes

There are several ways to get the client’s user name when running in Thin Client.  Here are 2 common methods.

A$CURRENT_USER
You can call A$CURRENT-USER to get a lot of information about the client, including the user-id.  If you use the application server’s login by setting iscobol.as.authentication=2 it will return that user name.  Otherwise it returns their operating system’s user name.  Here’s the syntax of that library routine.

   CALL A$CURRENT_USER USING ID
                             username
                             userAddr
                             userComp
                             threadID
                             prog
                            [type]
                            [loginTime]
                            [userInfo]
                     
GIVING returnCode

 

Using the windows API function “GetUserName” with CALL CLIENT
This method will get the user name on the local machine if you run in fat client, and the client machine if you run in thin client.  Here’s a code snippet as an example.

Please give the following code a try:

       program-id. prg.

      
working-storage section.
      
77   userName pic x(32).
      
77   len      pic 99 value 32.

      
procedure division.
       main.
          
call client "C$SETENV" using "dll_convention", "1".
          
call client "GetUserNameA" using by reference username
                                           
by reference
len
              on exception
                 call client "ADVAPI32.dll"
                 call client "GetUserNameA" using by reference username

                                            by reference len
           end-call.
           display userName.
           goback.

 

 
How to get the end user name in Thin Client.