How to get the user name with CSharp

How to get the user name with CSharp

When we talk about how to get the user name with CSharp, basically, we want to get the name of the object user and his attributes in the Active Directory.
We should have the knowledge regarding the users currently logged in, in our windows operating system. This technique then leads towards many ADS functionalities that can be addressed with programming code.Now lets see what has to be done but before we carry on, a network admin who also know programming the Active Directory can achieve the highest rank in the organization as a complete Network Engineer, not just like a configuration guy . The area which I will discuss , is all about working with Active Directory with CSharp. This is the thing that people must know because hard and fast rules of being a network admin may not going to work in achieving the title of Network Engineer. Unix admins learn C or C++ but here at Microsoft we can use the power of easy coding of .Net framework. At least we have to show this world that we are better than the best 😛
So here is the code

// Sample for the Environment.UserName property
using System;

class Sample
{
public static void Main()
{
Console.WriteLine();
// <-- Keep this information secure! -->
Console.WriteLine(“UserName: {0}”, Environment.UserName);
}
}

Output

Syed Adeel Ahmed
Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply