By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,066 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,066 IT Pros & Developers. It's quick & easy.

how to tell if local account is disabled with directoryservices.dll and vb.net

P: n/a
Does anyone know how to tell if a local user account on a member server is
disabled using the directoryservices dll and vb.net? I know since it is not
an LDAP server that i will have to use the WinNT provider. Any help would
be appreciated.

Thanks,

Brent Grooms
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Brent,
Does anyone know how to tell if a local user account on a member server is
disabled using the directoryservices dll and vb.net?


No problem - you just need to a) bind to the user using the WinNT
provider, and b) get the native ADSI "IADsUser" interface - that's the
easiest, since it has an attribute called "IsAccountDisabled". For
that to work, you'll also need to add another reference to your
project, to the COM "ActiveDs Type Library", and add a "using
ActiveDs; " line to the beginning of your source file.

Sample in C# - should be easy enough to translate to VB.NET:

private bool IsDisabled(string aUserPath)
{
bool bResult = false;
DirectoryEntry deObj = new DirectoryEntry(aUserPath);

// make sure it's a user - otherwise, we don't have
// the concept of "disabled", hence return false always
if(deObj.SchemaClassName.ToLower() == "user")
{
IADsUser intfUser = (deObj.NativeObject as IADsUser);
if(intfUser != null)
{
bResult = intfUser.AccountDisabled;
}
}

return bResult;
}

Now if you call this method like this, you should be getting back your
results:

bool bIsDisabled = IsDisabled("WinNT://<machine>/<username>,User");

e.g.

if(IsDisabled("WinNT://MyPC/Guest,User")
{
.........
}
HTH
MArc
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.