How do the thin client get the Windows username?

Question ID : 244
Created on 2015-04-20 at 7:53 AM
Author : Veryant Support [support@veryant.com]

Online URL : http://support.veryant.com/support/phpkb/question.php?ID=244



The most reliable way to retrieve this kind of info is by calling Windows functions.

The API function GetUserName does the trick.

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.


Back to Original Question