Last active
January 6, 2020 14:02
-
-
Save SamKr/43fc08ba124042e6d51df54acbea3fbe to your computer and use it in GitHub Desktop.
Search for the existance of a local user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.DirectoryServices.AccountManagement; | |
using (var pc = new PrincipalContext(ContextType.Machine)) | |
{ | |
var up = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "gebruiker2"); | |
var userExists = (up != null); | |
if (userExists) Console.WriteLine("user exists"); | |
else Console.WriteLine("user not found"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment