[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Finding the current log in user in windows

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
Shabzt
Asked:
Shabzt
  • 6
  • 4
  • 4
  • +4
1 Solution
 
CEHJCommented:
System.getProperty("user.name");

Can't get the permissions though
0
 
girionisCommented:
Use the proeprty: user.name
0
 
Ajay-SinghCommented:
system property "user.name" gives you that
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sciuriwareCommented:
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
 
ShabztAuthor Commented:
but how can we find the user type....and other details about this user
0
 
sciuriwareCommented:
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
 
WebstormCommented:
>> and other details about this user
You can get his home directory :
   System.getProperty("user.home");

0
 
bpmurrayCommented:
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
 
ShabztAuthor Commented:
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
 
ShabztAuthor Commented:
>> 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
 
sciuriwareCommented:
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
 
ShabztAuthor Commented:
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
 
sciuriwareCommented:
I have been searching for you, but ... no idea. I just never had this need.

;JOOP!
0
 
CEHJCommented:
Why do you want to know what type of user it is btw?
0
 
ShabztAuthor Commented:
Bcoz I am developing a custom made installer...and in that it will act as action...
0
 
CEHJCommented:
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
 
CEHJCommented:
So you need to know if it has write access?
=
So you need to know if it has install access?
0
 
ShabztAuthor Commented:
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
 
WebstormCommented:
>> 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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 6
  • 4
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now