How to find current user on the OS

Author: (apicaud)

Hi, I would like to known the name of the current user. I think, I can add advapi32.dll in a signature to call the function GetUserName but I don't known how make this integration. Have you a solution about the problem ? Regards


  1. In the download section of the Uniface Community, you find an article about integrationg Windows API from George Mockford. Success, Uli P.S. Nowadays you have a choice between GetUsernameA (ascii) and GetUsernameW (Unicode).

    Author: ulrich-merkel (
  2. Thanks, it's a good solution.

    I've integrated signature of GetUsernameA currently but I need also GetUsernameW for Unicode.



    Author: apicaud (
  3. Hi,

    As has been said above, the username is available in an environment variable, USERNAME on Windows, USER on Unix, SYS$LOGIN on VMS.

    Since 9.3, you can use

      myvar = $setting("", "MYVAR", "ENVDATA")

    to get the value of environment variables; in your case $setting("", "USERNAME", "ENVDATA") may do the trick. Note that $setting is currently undocumented and unsupported.


    Author: etienne (
  4. Hi Etienne,

    It's not a good solution, the envdata can be modify directly in a program.

    I use now directly the signature with dll of Windows (kernel32.dll) with the function getusernamea

        activate "kernel32".GETUSERNAMEA($$xUser, "255")

    And in the asn file, I specify also the dll.

    By, Antoine

    Author: apicaud (
  5. Hi Etienne and Antoine,

    i guess, there is no great difference between using the dll or the $setting method (which at this moment is new to me- thx for the hint).

    @Antoine: yes, you are right. The data can be modified. But isnt the question when?!

    see, what i mean is that if you open a shell (and i guess its somekind of what happens when uniface fires up), you get a set of environmentvars with you. If you choose to modify the data wiithin Uniface, then it isn't global (or is it?)

    The only chance we have is to rely on, whats in the environment. And so i guess, the result will be the same no matter which path you want to go.

    .oO(Or should i be so wrong in this?!)


    -GHAN- :)

    Author: -GHAN- (
  6. Hi there,

    maybe its not exactly what you look for but you could do the following without integrating a DLL ;)

    Simply look in the Environment!





    This should be possible since Windows 3.x i guess and is slightly compatible to UNIX/LINUX environments aswell. If you prefer to use a DLL for the JOB, the choice should be as mentioned from Uli Merkel


    a nice Weekend to you,



    Author: -GHAN- (