• Post Reply Bookmark Topic Watch Topic
  • New Topic

How tell if user is logged into computer (linux, windows..)?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way in Java to check to see if a computer on the network is locked or turned off? How would I do it for:

* Linux
* Windows
* Mac OSX
* Unix

Can each of those comp's be "locked" or logged off from?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no one?
 
John Kelty
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's anything provided in Java to do that. I would think you'd have to make a Runtime.exec call and issue an OS-specific call to get the list of users.

Would running a simple ping command for the machine's IP address work? That would be pretty OS-generic, but still require the use of Runtime.exec.

--John
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely, if a ping is sufficient, you can do that with java.net classes and do not need the expense of starting up a whole separate process to run the "ping" command. Also, using pure Java will be fully portable.

However, I suspect that the original poster wants more information than a simple ping can give. If so, then it does sound like platform-specific code is needed. This can be implemented by firing up a separate process to run a platform-specific command, or by using JNI. The former is easy but slow, while the latter is harder to program but much faster.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

One can check whether the machine is up or down, but not whether it is locked or loggedoff. More over the information you get from the machine totally depends on the O/S on which it is running. If it is running windows, you can get much information.

Advantage with java is you can use Raw Sockets with simple coding, unlike other languages.
 
James Collings
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Unix: System.exec and the 'who' command and then parse the results. I've not been able to find the corresponding windows command but I'm sure it is there somewhere.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!