Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.getProperty("user.name") returns HOSTNAME instead of currently logged username

Tags:

java

windows

Here

System.getProperty("user.name"); 

returns host-name of windows server 2008 machine instead of currently logged in user name.

Below is my code

final String user = System.getProperty("user.name");
logger.info("User Name : " + user);

I want to know how System.getProperty works in java and on windows server 2008? and why is it returning wrong value in this case?

like image 348
Rohan Avatar asked Aug 21 '13 09:08

Rohan


1 Answers

Just checked this: System.getProperty("user.name"); returns the value from environment variable USERNAME, so check what set USERNAME says in CMD window

like image 100
Gyro Gearless Avatar answered Oct 04 '22 20:10

Gyro Gearless