I am developing a C# windows service.
I need to know (from the service) who is the currently logged on user.
I tried to follow the answer in here with this code:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
string username = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
But the problem is that it works only on Windows 7, but on Windows 8 I get an empty string.
Was the WMI changed in Windows 8?