3

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.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
user1451111
  • 1,735
  • 3
  • 18
  • 30
  • possible duplicate of http://stackoverflow.com/questions/5067240/user-logged-into-remote-machine or http://stackoverflow.com/questions/14212155/how-to-get-logged-on-users-with-their-status-on-remote-machine – Jonesopolis Mar 24 '14 at 12:21
  • The first link is not of use to me beause I am unable to see System.Management.ConnectionOptions class in my intellisense and the second link is also not useful because I am unable to see 'ManagementScope' class. – user1451111 Mar 24 '14 at 13:30
  • I have tried all the available answers from this site but all of them end up with the following exception, "RPC server is unavailable". Where I can successfully log on them using remote desktop viewer. – user1451111 Mar 25 '14 at 11:52

1 Answers1

10

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

TheMightyX2Y
  • 1,473
  • 1
  • 16
  • 24