Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

windows OS user name

Status
Not open for further replies.

FALCONSEYE

Programmer
Jul 30, 2004
1,158
0
0
US
is there a way to get the user's windows OS login with java? if so, how?
thanks for the help in advance
 
You can try to retrieve the user's account name:

Code:
System.getProperty("user.name");



---
There is no Knowledge that is not power
---
 
Hmmm. Trouble is that you can invoke the java program with -Duser.name=SomeoneElse or put this in a properties file and then you don't get the windows OS user name, but "SomeoneElse" instead, so this can't be relied upon.
So I'm still looking for a way to do it - I suspect native code is unavoidable...

Graeme
 
Most versions of windows allow unnamed login too.

And you may fake the username on windows by 'SET USER=nobody' or in a similar way - which is possible on linux too.

That doesn't mean that the User home is changed with that technique too, or permissions.

Windows has never been a real multiuser system :)

seeking a job as java-programmer in Berlin:
 
Stefanwagner

I have tried the set user and set username environment hack, and it did not alter the result, either for a java app calling the code above, or a similar .net app, or an asp.net application using windows integrated security (altering the environment variable does not affect the user that the server sees).

What am I missing?

Thanks
Mark

Mark [openup]
 
i get the username by

System.getProperty("user.name");

but couldn't get the user password. The application runs on the intranet so there won't be any security problem. The OS is Windows XP Pro.

Mr Oswald, even if i have say 3 users setup on my local machine, when i run LuckyStar's code it just gives me the current username, not the others. So, won't it help?

By the way, did anybody manage to get the user password as well?
 
You cannot get the user's password from the System properties !
If you are authenticating via LDAP/AD - then use that to authenticate.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top