*
The moose likes Java in General and the fly likes get the currently logged user(urgent) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "get the currently logged user(urgent)" Watch "get the currently logged user(urgent)" New topic
Author

get the currently logged user(urgent)

netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hai, I want to know the user who is currently logged in the machine.If possible post the code too,lets consider windows as the O.S.Now I want to get the user from java,where I customize the perferences for my aplication based on the user logged in.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
<pre> System.out.println(System.getProperty("user.name"));</pre>
See the API for System.getProperties() for a list of other proerties you can access. Additional properties may be available on your system - this list is just the standard ones.


"I'm not back." - Bill Harding, Twister
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
This works for me on Win2K:
System.getProperty("user.name")
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hi. it's working fine,but the problem is if the user is a guest it displays unknown.Is there anyway to identify the guest user too.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
<pre> System.out.println("Who the heck are you?");</pre>
Seriously, if the system allows people to log in with no account or password, then you will have to ask them.
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Thank you Jim,but I just wanted the system to return "Guest", instead of the username.Anyhow thank you so much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the currently logged user(urgent)