Link to home
Start Free TrialLog in
Avatar of wierd_dave
wierd_dave

asked on

Getting NT Status - logged on / off or locked

How can I tell if a computer has someone logged in? I need to write a program that tells if someone is at their desk, the idea being that if they are, they're most likely to also be logged in and not be logged out or locked. I need a "yes" answer from the program for a logged in and a "no" answer for any other state. I can then write this to a web page in my usual way.

Cheers

Dave
Avatar of inpras
inpras

I think U need to have an adapater installed on the end m/c which monitors the events on the end m/c logs them and sends to server (for this U can use sockets)..
Hope this helps
ASKER CERTIFIED SOLUTION
Avatar of shaig
shaig
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wierd_dave

ASKER

I can handle him being away! I'm having to put up with an endless stream of students looking for a certain research assistant, so if I can put whether he's in or not on a web page, I'll be a happy chappie.

Would the computer being locked affect the operation of a program?

Dave
Avatar of jkr
The most compatible way for all MS platforms would be to enumerate the entries in 'HKEY_USERS' - see http://www.sysinternals.com/misc.htm#loggedon for a source code sample...
Looking at this program, it only checks if the computer has a user loged in or not, ragardless of whether it is locked or not. We very rarely log off in this office, preferring to lock so we can still access each others resources.
A locked machine is the best indication that we are not in.
If it's not locked and unused, we've popped to the coffee machine.
If it's logged out, we're probably rebooting or logging back in as an administrator.
If it's locked we've left the building for whatever reason.
Err - your question was "How can I tell if a computer has someone logged in?".

My answer was the answer to this very question... It's not good practice here to ask questions, reject correct answers along with telling 'no, I wanted to know something else'
OK, I don't appear to have been as clear as I thought I had been. When I said "I need a "yes" answer from the program for a logged in and a "no" answer for any other state." I meant that if the machine is logged in and not locked, then I can assume someone is sat there working. If it is logged off or is logged in to, but has been locked, they probably are not working here.

I know what I meant, I just didn't say it quite right.

Dave
I still think this is a bad mechanism.
The best way to tell if a user is using his compuetr is to check just that: keyboard and mouse activity.

How does the suggested mechanizm deal with a user that shuts his computer down (vecation, sick, etc.).
I'm working on this activity monitor right now. If the mouse hasn't moved or the keyboard been touched in 15 minutes say, I'll log him as been out.
If he logs out the program will recieve a quit message and he can be instantly log as away.
Indeed it seems simpler this way.
Yap, thats the idea.
To detect if there is a logged on interactive user, enumerate the window stations until you find WinSta0.  Then use that handle to enumerate the desktops.  If you find WinSta0\default, then there is an interactive user logged in.  If this desktop doesn't exist, then there is no interactive user logged in.
So, what will it be wierd dave?
I went for the windows hooks. Placed in a dll they should be able to log all activity from what MSDN tells me.

This has been a thread full of good stuff as far as I'm concerned - cheers to all.

Dave