Updated 2011-09-24 02:45:50 by RLE

Alastair Davies asks: how can one determine the current user name? This is often handy when pre-filling default values for an entry field in a form, for example.

There may be a suitable environment variable: for example, Windows 2000 & XP set the variable USERNAME and MacOS X sets the variable USER. These will be present in the magic env array. Most Linux systems (debian, ubuntu, suse) nowadays also have USER variable, but it is not clear if it is ubiquitous for all POSIX systems.

On POSIX systems, the TclX command id user will return the user's login name. Independent of TclX, but still only for POSIX systems, there is a critcl implemention of userid. On Windows 2000 & XP, the twapi command get_current_user will return the user's full name. Windows 98 & earlier do not really support the concept of mulitple users.

Is there anything known to work reliably cross-platform?

20 March 2006

NEM: $::tcl_platform(user)