Skip to Content

How do the thin client get the Windows username?

Estimated Reading Time: < 1 Minute

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.
How do the thin client get the Windows username?

Powered by PHPKB (Knowledge Base Software)