I have an application that checks to see if a USER exists (if not create it) every time it starts, this is done as follows:
bool bUserExists = false;
DirectoryEntry dirEntryLocalMachine =
new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntries dirEntries = dirEntryLocalMachine.Children;
foreach (DirectoryEntry dirEntryUser in dirEntries)
{
bUserExists = dirEntryUser.Name.Equals("UserName",
StringComparison.CurrentCultureIgnoreCase);
if (bUserExists)
break;
}
Problem is on the majority of the systems where it is deployed this can take 6 - 10 seconds, which is too long ... I need to find a way to reduce this (as much as possible). So is there a BETTER or FASTER way I can use to verify if a user exists on the system or not?
I know there are other ways to solve this, like have the other applications sleep for 10 seconds, or have this tool send a message when he is ready, etc... but if I can greatly reduce the time it takes to find the user it would make my life much easier.
Any help would be greatly appreciated. Thanks,