Get current logged on username - Microsoft Windows
Hi
I need to get the username of the current active logged on user.
I have tried
Code :
System.getProperty("user.name");
And that does work however this is where it becomes a little tricky.
The java app will run as a service using the NetworkService service account and when using the above code it returns 'NetworkService'.
What I want is to get the java code to return the current logged on user, not the user who is running the java app.
Is there a way of achieving this?
Re: Get current logged on username - Microsoft Windows
Quote:
Originally Posted by
mds1256
Hi
I need to get the username of the current active logged on user.
I have tried
Code :
System.getProperty("user.name");
And that does work however this is where it becomes a little tricky.
The java app will run as a service using the NetworkService service account and when using the above code it returns 'NetworkService'.
What I want is to get the java code to return the current logged on user, not the user who is running the java app.
Is there a way of achieving this?
What exactly do you need it for? Depending on what you're trying to do there may be other workarounds. For instance, %USERNAME% MIGHT work if you're trying to find a file. Otherwise there are other things we can try.
Thanks!
Re: Get current logged on username - Microsoft Windows
Hi
Thanks for the reply, basically it is an app for reporting user application usage, e.g. what apps they open and when.
Now when running this as a network service it just reports that the network service is the user and not the current logged on user.
Thanks