How to get the current Windows username in C#?
Hello everyone! I'm a beginner C# developer and I'm writing a small application for internal use in our company. I need the program to automatically determine which employee is currently working at the computer and log that name.\n\nI tried using `Environment.UserName`, but it seems to return not exactly what I need. I also heard about `WindowsIdentity.GetCurrent()`, but I don't understand the difference between these approaches.\n\nHere's an example of my code that I thought should work:\n\n```csharp\nusing System;\n\nclass Program\n{\n static void Main()\n {\n string currentUser = Environment.UserName;\n Console.WriteLine("Current user: " + currentUser);\n }\n}\n```\n\nThe problem is that when I run the application through Task Scheduler