Reputation: 1943
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:
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.
Upvotes: 3
Views: 9853
Reputation: 1503
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
Upvotes: 10