Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Get current logged on username - Microsoft Windows

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Get current logged on username - Microsoft Windows

    Hi

    I need to get the username of the current active logged on user.

    I have tried

    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?


  2. #2
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Get current logged on username - Microsoft Windows

    Quote Originally Posted by mds1256 View Post
    Hi

    I need to get the username of the current active logged on user.

    I have tried

    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!

  3. #3
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default 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

Similar Threads

  1. Replies: 21
    Last Post: November 27th, 2012, 09:58 PM
  2. HOW TO REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
    By divyatejak in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: March 6th, 2012, 04:19 AM
  3. Replies: 1
    Last Post: September 9th, 2011, 02:30 PM