How to get list of all logged in users using

c#, windows

Solution

This query give to you all the logged users

ManagementObjectSearcher query= new ManagementObjectSearcher("SELECT * FROM Win32_UserProfile WHERE Loaded = True");

You also have other parameters like `LastUseTime` into Win32_UserProfile

Problem

How can I get a list of usernames and their activity times on a remote machine, using C#? For example, if there is a Windows machine named 'ABC-PC' and there are currently three active users on it named 'X', 'Y' and 'Z'. Where: - 'X' is currently active - 'Y' is idle for last 4 minutes - 'Z' is idle for last 20 minutes I want to write code that fetches me all of these mentioned information. I am sure there is some .NET API but which one is that I am unsure.

Original source

Related problems