C# Get Currently logged in windows user
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Security.Principal; /* Namespace needed to get currently logged in user */ namespace SecurityModules { [TestClass] public class Security { [TestMethod] public void GetCurrentUser() { // Act var currentlyLoggedInUser = WindowsIdentity.GetCurrent().Name; // Assert Assert.IsFalse(string.IsNullOrEmpty(currentlyLoggedInUser)); } } }
Comments
Post a Comment