In this example, i’ll show you How to getusername in c#.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | foreach (System.Management.ManagementObject Process in Processes.Get()) { if (Process["ExecutablePath"] != null && System.IO.Path.GetFileName(Process["ExecutablePath"].ToString()).ToLower() == "explorer.exe" ) { string[] OwnerInfo = new string[2]; Process.InvokeMethod("GetOwner", (object[])OwnerInfo); Console.WriteLine(string.Format("Windows Logged-in Interactive UserName={0}", OwnerInfo[0])); break; } } |