Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding the current log in user in windows

Posted on 2006-07-11
19
Medium Priority
?
242 Views
Last Modified: 2010-03-31
How can I find that which user is currently logged in windows using java? I want user name and user type(like administrator,user...).My target os is Windows XP.
0
Comment
Question by:Shabzt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
  • +4
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17079470
System.getProperty("user.name");

Can't get the permissions though
0
 
LVL 35

Expert Comment

by:girionis
ID: 17079474
Use the proeprty: user.name
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17079475
system property "user.name" gives you that
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 24

Expert Comment

by:sciuriware
ID: 17079509
You should be able to find some characteristics of the current user in his/her
C:\Documents and Settings\<username as above>\NTuser.dat
It will be hard work, because that's the binary, per-user, Registry, but what you want is inthere.

;JOOP!
0
 

Author Comment

by:Shabzt
ID: 17079605
but how can we find the user type....and other details about this user
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17079662
Use Regedit.exe to see the readable part of "Current User".
Then you might try to read the binaries from that file.

Of course direct Registry access would be better, but I leave that to you.

;JOOP!
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 17079858
>> and other details about this user
You can get his home directory :
   System.getProperty("user.home");

0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17080177
What exactly are you trying to do? If you want to find out if the current user has permissions to do something, you can use the class SecurityManager and call checkpermission on the action.
0
 

Author Comment

by:Shabzt
ID: 17080215
I want to check first before starting of my program that which user has logged in. If it is administrator then do this. If it is "user" then do that.
0
 

Author Comment

by:Shabzt
ID: 17080223
>> Use Regedit.exe to see the readable part of "Current User".
>>Then you might try to read the binaries from that file.

>>Of course direct Registry access would be better, but I leave that to you.

Which registry key I should check?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17080302
If it only concerns if someone is Administrator (or member) you might
check his access rights on a restricted area.
Locate a folder of file "private" to Administrator and use new File(...).canWrite();

;JOOP!
0
 

Author Comment

by:Shabzt
ID: 17080375
yes its a good idea...let me try this...But it would have been good for me if  some how I can know the registry key from where I can get the current user type...any idea ?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17080493
I have been searching for you, but ... no idea. I just never had this need.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17080911
Why do you want to know what type of user it is btw?
0
 

Author Comment

by:Shabzt
ID: 17080938
Bcoz I am developing a custom made installer...and in that it will act as action...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17081039
So you need to know if it has write access?

Runtime.exec

cacls "C:\Documents and Settings\Administrator"

and if you're not an admin, it'll come back access denied
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17081044
So you need to know if it has write access?
=
So you need to know if it has install access?
0
 

Author Comment

by:Shabzt
ID: 17081079
User can use this action according to his own requirement....n I want all the details of user, because this action should be scalable...
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 2000 total points
ID: 17081468
>> cacls "C:\Documents and Settings\Administrator"
Won't work on non-english Windows.
For example in french :
->  cacls "C:\Documents and Settings\Administrateur"

Also Windows maybe installed on another disk drive ->
   File f=new File(System.getProperty("user.home"));
   f=new File(f.getParentFile(),"Administrator"); // or "Administrateur", ...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question