How to check if a user is loged in to computer or not

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

How to check if a user is loged in to computer or not

Post by dkurfurst »

I need to create a test that checks if someone is logged into a computer or not. We have a process that must be running on a users workstation - I am currently monitoring the process and also have a master test that the process monitor is dependatnt on that check to make sure the machine is on (pingable). The problem with this is I get false alarms if someone just logs out. the process is obviopusly dead but the machine is pingable so the master is tru and I get allerts that the proccess has died. I need to ad another master test that checks to see if the machine has anyone logged in or not. Can this be done easily ? is there a proccess or something else I can check if someone is logged in or not? The computers are all XP and login to a domain.

Any help is appreciated
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

As I know Windows does not provide any conventional method to check is user logged in. There are various tricks, e.g. check for Window classes...
We can create usility for you but this utility will be able to check local system only. If you need to monitor remote system, you will have to install RMA (Remote Monitoring Agent) on that system

Regards
Alex
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Post by dkurfurst »

I am a little confused about local system or remote. I am checking a few dozen workstations for the same process but need to check if somone is logged in to the computer / domain. All of the computers are on the same subnet and are located in the same facility.
Will I need to run the utility on all of the computers (localy) or can the utility run from hostmonitor?

thanks
Don
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

This utility will not be able to retrieve information from remote system...

I just recall.. WMI may help. You may setup WMI test using query like "select * from Win32_LoggedOnUser" and set "Alert if row count is < than 1" option

Regards
Alex
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

Watch out - the 'select * from Win32_LoggedOnUser' will also give a count of Terminal Services (Remote Desktop/RDP) sessions. You may not be using any, but then again you are probably only running the process on the console session.

I believe you could make a master test out of posting in the query entry
Select UserName from Win32_ComputerSystem
And alert if UserName = "". This only looks at the local (console) session.

Personally I would do it all as a single VBscript test.

Properly implemented you could script this whole thing as one test.
You could eliminate the need for a ping test by WMI querying for the currently logged in user. Set up an error trap route, because if the query errs the computer wasn't responding (similar to ping failure). Only if the computer responds with a logged in user name would you check the existence of the process.

I don't have a complete script for you to use, but if you're willing to join the dark side :evil: and do a little VBScripting, here's a code snippet for the logged on user part that might help:

Code: Select all

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
     CurrUser = objItem.UserName
Next
If CurrUser <> "" Then
(check for the existence of the process)
. . .
('strComputer' is a variable that would be supplied as a script parameter)

Of course I'm assuming you only alarm if Machine=ON, UserName<>"", and Process NotFound. Additional iterations would require a bit more planning.
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Post by dkurfurst »

Thanks for all the great suggestions and reccomendations. looks like the "Select UserName from Win32_ComputerSystem" is a winner. I only whish that there was a way to use just one master test for all computers, but no worries replicator works like a charm and cuts down on the time it takes to create the 3 -4 dozen tests I need.
Thanks Again
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

I only whish that there was a way to use just one master test for all computers
Once again, if you're willing to 'step outside' and do a little scripting, you could do it this way. Personally, I would stick to one machine/test as much as possible, otherwise you loose the granularity of being able to report on individual system status.

There is still value in combining the three statuses a machine can exhibit (System responds, User logged on, Process running) into one scripted test. I've given you a bit of a head start on that one. If you choose to take on that challenge, please share your code in the Library. :wink:

I'm tempted to take my own suggestion and give it a go myself - in my spare time of course. 8)

Regards,
Joel
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Conditional testing

Post by dkurfurst »

Ok, I have my tests setup and all is great except for one issue......

I have 1 test setup for checking if a particular process is runing or not on end users local computers. this test is dependant upon two other tests which is - one test pings the workstation to see if its up, the second uses the wmi interface to see if a user is logged in the computer. For the most part this works great I get an alert if a user is logged in and he shuts down / kills the application that we are monitoring on his desktop. we have this set to alert us 3 times and this works fine. My issue is at the end of the day when users are leaving for the day and shutting down there systems, I get false alarms that the process has been killed. Is there any way that we can eliminate these false alarms?
Any ideas???
Thanks
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I assume system was shutdown between ping and process test executions, that's why HostMonitor started action.
You may decrease value of "Consider status of the master test obsolete after N seconds" option. Default value is 60 sec. You may set it to 15 or 10 seconds or even 2 seconds (only in case you do not use a lot of master-dependant relations!)

PS Option located on Behavior page in the Options dialog

Regards
Alex
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Post by dkurfurst »

KS-Soft wrote:I assume system was shutdown between ping and process test executions, that's why HostMonitor started action.
You may decrease value of "Consider status of the master test obsolete after N seconds" option. Default value is 60 sec. You may set it to 15 or 10 seconds or even 2 seconds (only in case you do not use a lot of master-dependant relations!)

PS Option located on Behavior page in the Options dialog

Regards
Alex
Is there a WMI test that I can use to check if the machine is being shut down? The problem that we are encoutering is that when the machine is issued a shutdown command, naturally any running processes and applications are shut down first and host monitor may test during this time and see that the machine is pigable and the user is logged in, but the application is shut down. If there was a way to test if the PC was being shut down or logged off first, I would assume that this would eliminate our issues.

Thanks
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

You might be able to use WIN32_OperatingSystem/Status, or Win32_ComputerSystem/BootupState, or you could use the running status for a marquee service/process. But the problem is that the remote system may already be in a pingable but non-responsive state if it's in the middle of shutting down services, especially your RMA agent (if you're using one), WMI, or RPC, or if it's in the middle of starting back up. :-?
You might be better off establishing a warning status after 1-2 non-responsive status checks and bad status after 2-3, depending on how long, on average, the system takes to restart.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I think greyhat64 is right. You may start alerts after 2nd or 3rd consecutive failure.
If you are using long test interval for this item, you may start "change test interval" action after 1st failure (e.g. to repeat test probe after 1 min).
Do not forget to add "change test interval: restore original value" action into "good" section of the profile.

Regards
Alex
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Post by dkurfurst »

KS-Soft wrote:I think greyhat64 is right. You may start alerts after 2nd or 3rd consecutive failure.
If you are using long test interval for this item, you may start "change test interval" action after 1st failure (e.g. to repeat test probe after 1 min).
Do not forget to add "change test interval: restore original value" action into "good" section of the profile.

Regards
Alex
Excuse my ignorance, but where do I set this?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

What exactly are you asking about?

How to start alert after 2nd consecutive "bad" result?
Use Action Properties dialog to change action options:
http://www.ks-soft.net/hostmon.eng/mfra ... properties

How to add "change test interval" action into profile?
As usually: open Action Profiles dialog and add new action into profile
http://www.ks-soft.net/hostmon.eng/mfra ... m#profiles

Regards
Alex
dkurfurst
Posts: 61
Joined: Thu Sep 22, 2005 10:13 am

Post by dkurfurst »

KS-Soft wrote:What exactly are you asking about?

How to start alert after 2nd consecutive "bad" result?
Use Action Properties dialog to change action options:
http://www.ks-soft.net/hostmon.eng/mfra ... properties

How to add "change test interval" action into profile?
As usually: open Action Profiles dialog and add new action into profile
http://www.ks-soft.net/hostmon.eng/mfra ... m#profiles

Regards
Alex
Alex
I am asking how to change the test interval in the action profile - I am not certian where this gets set.......
Nevr mind... did not se it under the action profiles... I understand!
Post Reply