This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I am currently trying to retrieve the session ID of my Windows user name through Java.
Manually I can do this by entering "query session" in MS command prompt. This shows the sessionname, username, id, state, type and device of all connected users including remote access sessions. The column id represents the session id. This is the exact data that I need in my Java application.
Is there an API in Java that I could use to retrieve that session id across operating systems?
Not all OSs will have such a thing. UNIX doesn't. There are vaguely related concepts on other OSs that you might decide to use -- process IDs of login shells, for example -- but nothing precisely analogous. I think you're going to have to do this yourself. As far as APIs -- using Runtime.exec() to run the "query session" command is about it.