Kaseya Community

Improving Logged in User Detection

  • Procedure isUserLoggedIn Test.zip

    I have noticed a few times now that the "is User Logged in" If statement does always work as the agent is not always able to detect if somebody is logged into a machine or not.

    It appears to have something to do with this "KaUsrTsk.exe" executable not running.

    This issue can be extremely troublesome especially when you need to reboot a machine during maintenance or power it down post maintenance and don't want to do so if somebody is logged on to the machine.

    I found a workaround for Windows machines by using the "UserName" value in the "Win32_ComputerSystem" WMI class. This "UserName" value does not exist if no users are logged into the machine.

    There are actually a few WMI values that has user session values however this one seems to work fine.

    So far I have only tested it on a Windows 7 machines but it looks promising. I still need to check how it works with RDP sessions and all the other Windows versions.

    I have a attached a sample script that checks for logged in users and reboots the machine if anybody wants to give it a try.

  • Hey HardKnoX. I had an issue with the "isLuserLoggedIn" check with one of my agent procedures, and found this post. I tried the agent procedure, and it did not work for Windows 8.1. Have you found any other methods that work well for determining whether a user is logged in or not? The current check, in my opinion, is not adequate and has caused some servers to reboot at very inappropriate times.

  • Hi thanks for your input on this, its good to get feedback so that I can make improvements where possible and since it has been almost a year since I posted this it is always possible for something to change.

    Note that I'm currently on Kaseya Version 6.5 and I wrote this procedure while I was still using 6.3. I retested this procedure on seven Windows 8.1 Enterprise/Professional computers and found that the WMI part that I added still works for me.

    If you run this against  Windows 8.1 Basic install it might not work as Microsoft removed WMI from Windows Home Editions in the past. I can't verify if this is the case for the Basic Edition of Windows 8.1 as I currently don't have access to any to try.

    Regarding the server reboot schedule issue;

    I got around the Server reboot issue by adding additional WMI checks to look at the current time on the server and comparing it to a predefined time window.

    This worked so well that one of my ex-colleagues tried to schedule this server reboot procedure with a predefined window of 10PM to 6AM at 7PM and could not understand why the server did not reboot until I pointed him to the procedure name and description which explained why it failed to reboot the server.

    I have a sample procedure on how to work with time in agent procedure in the following post: community.kaseya.com/.../52642.aspx