Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Programatic Way to Determine Current Windows User

Tags:

java

windows

I see many similar questions, however I want to find the Username of the currently logged in user using Java.

Its probably something like:

System.getProperty(current.user);

But, I'm not quite sure.

like image 329
jjnguy Avatar asked Aug 28 '08 00:08

jjnguy


3 Answers

You're actually really close. This is what you're looking for:

System.getProperty("user.name")
like image 62
Chris Bunch Avatar answered Sep 22 '22 09:09

Chris Bunch


The commonly available system properties are documented in the System.getProperties() method.

As Chris said "user.name" is the property to get the user running your app.

like image 31
John Meagher Avatar answered Sep 20 '22 09:09

John Meagher


As mentioned above (and linked for Java 6), to get the current user:

System.getProperty("user.name")

For Java 7: System.getProperties()

For Java 8: System.getProperties()

For Java 9: System.getProperties()

For Java 10: System.getProperties()

For Java 11: System.getProperties()

For Java 12: System.getProperties()

For Java 13: System.getProperties()

For Java 14: System.getProperties()

For Java 15: System.getProperties()

For Java 16: System.getProperties()

For Java 17: System.getProperties()

like image 33
marklark Avatar answered Sep 21 '22 09:09

marklark