I am having difficulty getting the User Name of a person logged into a machine using a windows service.
When using both System.Environment.UserName or WindowsIdentity.Ge
Try this:
var connectionOptions = new ConnectionOptions();
var scope = new System.Management.ManagementScope("\\\\localhost", connectionOptions);
var query = new System.Management.ObjectQuery("select * from Win32_ComputerSystem");
var searcher = new ManagementObjectSearcher(scope, query);
foreach (var row in searcher.Get())
{
Console.WriteLine(row["UserName"].ToString().ToLower());
}