• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no one?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic