Getting Computer Name and Computer User Name in C# Projects

I was working on a small project in which i was trying to get the User account name and User Computer Name on windows form so i tried some codes & in last i came up with this code. It gives System Name and System User Name. By this code you can get computer identification in your simple projects.

For Computer Name

Console.WriteLine(System.Environment.MachineName);

Output :

For User Account Name

Console.WriteLine(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());

Output :

2 thoughts on “Getting Computer Name and Computer User Name in C# Projects”

Comments are closed.