maybe you are missing the USERNAME environment variable for some reason. Run the set command and it will list the environment variables and their values. My XP has USERNAME and I didn't add it, so XP has it.. it's strange yours doesn't. But run set and see what you have
A bunch of environment variables have the user
TEMP=C:\DOCUME~1\User\LOCALS~1\Temp
TMP=C:\DOCUME~1\User\LOCALS~1\Temp
USERNAME=user
USERPROFILE=C:\Documents and Settings\user
Added
In an example similar to the one you are in.. Here I have logged into the machine remotely, it runs bvsshserver (bitvise ssh server aka winsshd) (which when logged into even from cygwin client, will give a windows command line) though openssh server via cygwin gives bash.. You can use the openssh client in cygwin to log into bitvise sshd and get a windows command line
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\WINSSH~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\WINSSH~1\LOCALS~1\Temp
USERNAME=WinSSHD_VirtualUsers
USERPROFILE=C:\Documents and Settings\WinSSHD_VirtualUsers
VIRTGROUP=Virtual Users
VIRTUSER=user
windir=C:\WINDOWS
C:\>whoami
WinSSHD_VirtualUsers
C:\>
In this case "VIRTUSER" has the username, though different to the one shown by whoami.
What SSH server(or remote logging in program server) does your XP machine run?
It works in Windows7. – cliff2310 – 2015-05-25T22:41:26.080
1@cliff2310 you say it works on 7 but can you not see he tagged this XP and is asking about XP (That said, it should work on XP too) – barlop – 2015-05-25T22:44:11.570
1It works fine on my XP system. Your observation will happen only if
username
is either not set, or set to the literal string%username%
. To find out which, typeset username
. Both are unlikely, but my best guess is that you have run a batch file which usesusername
as a work variable and clears it on exit, so search your batch files for the stringusername
(case insensitive search). – AFH – 2015-05-25T23:00:37.390"As I said, it's a pentesting lab with deliberately broken machines." -- voting to close as off topic – DavidPostill – 2015-05-25T23:43:21.937
"deliberately broken" is to be understood in the sense of badly maintained, not in the sense of artificially misconfigured machines that would never be seen in the wild. – countermode – 2015-05-26T00:34:56.850