How to

get current Windows user

Published: 13. December 2008 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: Windows » Authorization
Tags: C# Security Windows Winforms
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Security.Principal;

Code

WindowsIdentity user = WindowsIdentity.GetCurrent();

Console.WriteLine(user.Name);
Console Output:
COMPUTER-NAME\Administrator
Send us feedback about this snippet »



Related Snippets: