Enumerate Users

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

How can I get a list of all users currently logged into a Windows Server?
My program will be a windows service that has administrative access, so I
should have the correct access to do this.

Thanks for any help,
Bryan
 
PLEEEEEEEEEEEEEEEEEEEASE HELP...

I have tried many things, but just cant seem to get it!.. The closest I
have come is to get a list of "LogonId" that represent a connection...
If anyone has any tips I sure would appreciate it...

TIA,
Bryan

[snip]

String ToClient = "";
//SelectQuery query = new SelectQuery("Win32_NetworkClient"); // NO
(returns network info)
//SelectQuery query = new SelectQuery("Win32_NetworkConnection"); // NO
(returns nothing!)
SelectQuery query = new SelectQuery("Win32_LogonSession"); // NO (returns
some kind of number (Login ID) rahter than the actual user ID)
//SelectQuery query = new SelectQuery("Win32_Account"); // NO (returns
everything...)
//SelectQuery query = new SelectQuery("Win32_ServerConnection"); // NO
(returns nothing!)
//SelectQuery query = new SelectQuery("Win32_ServerSession"); // NO
(returns nothing!)
//SelectQuery query = new SelectQuery("Win32_UserAccount"); // Returns
info as expected (but returns all). "Name" is the User ID

try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get())
{
ToClient += "~" + (String)mo["Caption"] + ", " + (String)mo["Description"]
+ ", " + (String)mo["LogonId"] + ", " + (String)mo["Name"] + ", " +
(String)mo["Status"];

}
} catch (Exception e) {
ToClient += "Error: " + e.ToString();
}

return ToClient;
 
Back
Top