dcsimg
Results 1 to 2 of 2

Thread: How do I get the username of the person who is currently using the computer?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    183

    How do I get the username of the person who is currently using the computer?

    I'm developing a Java application that is supposed to be able to figure out who's currently using the computer and log him or her out. The app is supposed to run under an administrator account that the person who is using the computer is not logged in as.

    I want the app to work on non-Windows PCs. For now, I think I'll stick to supporting Unix-based OSes. Windows users will have to install Cygwin to use my app.
    Do not read this sentence.
    You read that last one, didn't you?
    Darn. You now read the previous two.

    Check out my pins on Pinterest!

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    183

    Re: How do I get the username of the person who is currently using the computer?

    I am going to implement the following code into my app. It doesn't get the name of the user that is currently using the computer, but I can use the function to present a list of users. I'll let the end user decide which user to log out.

    Code:
    private static String[] loggedInUsers() throws IOException
    {
    	Runtime runtime = Runtime.getRuntime();
    	String[] output;
    	Process whoProcess = runtime.exec("who -q");
    	InputStream inputStream = whoProcess.getInputStream();
    	InputStreamReader streamReader = new InputStreamReader (inputStream);
    	BufferedReader bufferedReader = new BufferedReader(streamReader);
    	String line = bufferedReader.readLine();
    	output = line.split("  ");
    	return output;
    }
    Do not read this sentence.
    You read that last one, didn't you?
    Darn. You now read the previous two.

    Check out my pins on Pinterest!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width