H
Heike Pertzel
Hallo NG!
I would like to get the name of the user logged on on a another computer.
I've written the following code which gives me the LogonId of this user.
But getting with this Id the name of the user doesn't work.
I would appreciate every hint or help!
Regards
Heike Pertzel
******************************************************************************************************
using System.Management;
string UserLogonId ;
string Username;
ManagementScope msc = new ManagementScope("\\\\" + IP of the OTHER computer
+ "\\root\\cimv2");
string queryString = "select LogonId from win32_logonsession where logontype
= 2";
query = new ManagementObjectSearcher(msc, new SelectQuery(queryString));
foreach( ManagementObject mo in query.Get())
{
UserLogonId = mo["LogonId"].ToString(); // WORKS !!!!!!
RelatedObjectQuery relatedQuery = new RelatedObjectQuery("associators of
{Win32_LogonSession.LogonId='" + mo["LogonId"]+ "'}WHERE AssocClass =
Win32_LoggedOnUser");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(msc,
relatedQuery);
foreach (ManagementObject mob in searcher.Get())
{
Username = mob["Caption"] + " " + mob["Domain"] + " " + mob["Name"];
// DOESN'T WORK !!!!!!! they are always empty strings
}
}
******************************************************************************************************
I would like to get the name of the user logged on on a another computer.
I've written the following code which gives me the LogonId of this user.
But getting with this Id the name of the user doesn't work.
I would appreciate every hint or help!
Regards
Heike Pertzel
******************************************************************************************************
using System.Management;
string UserLogonId ;
string Username;
ManagementScope msc = new ManagementScope("\\\\" + IP of the OTHER computer
+ "\\root\\cimv2");
string queryString = "select LogonId from win32_logonsession where logontype
= 2";
query = new ManagementObjectSearcher(msc, new SelectQuery(queryString));
foreach( ManagementObject mo in query.Get())
{
UserLogonId = mo["LogonId"].ToString(); // WORKS !!!!!!
RelatedObjectQuery relatedQuery = new RelatedObjectQuery("associators of
{Win32_LogonSession.LogonId='" + mo["LogonId"]+ "'}WHERE AssocClass =
Win32_LoggedOnUser");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(msc,
relatedQuery);
foreach (ManagementObject mob in searcher.Get())
{
Username = mob["Caption"] + " " + mob["Domain"] + " " + mob["Name"];
// DOESN'T WORK !!!!!!! they are always empty strings
}
}
******************************************************************************************************