[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

User Search Code Throws on Vista

coconet

4/8/2008 8:03:00 PM




I am trying to create a user on a Vista Ultimate system, only if it
does not exist. This code throws:

"
The user name could not be found. (Exception from HRESULT: 0x800708AD)
"

I know the user name could not be found - that is why I am checking!
What is the proper syntax to let this check properly work.

Thanks.

string local = "WinNT://" + Environment.MachineName + ",computer";
DirectoryEntry root = new DirectoryEntry( local );
DirectoryEntry entry = null;
if (root.Children.Find("TestAccount","User") == null) // <-throws
{
// ...make new user...
}

..NET Framework 3.5 Console app.