C#: How to get your computer and user name.

If you want to get your computer and user name from Windows in C# try this by using the WindowsIdentity class from System.Security.Principal namespace:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.Out.WriteLine(WindowsIdentity.GetCurrent().Name);
        }
    }
}
Shares