Friday, February 12, 2010

Check dynamically if the Logon User already exists

public bool UserExists(string UserName)
{

DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
foreach (DirectoryEntry child in directoryEntry.Children)
{
if (child.SchemaClassName == "User")
{
if (child.Name == UserName)
return false;
}
}
return true;
}

No comments:

Post a Comment