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.
Article ID: 244
Created: April 20, 2015
Last Updated: April 20, 2015
Author: Support KB Author
Online URL: https://support.veryant.com/phpkb/article.php?id=244