Update AD with VB.NET

J

jimstruckster

Hey everyone,
I'm working on a project to set up a new user in AD using VB. I
have the connection working and I'm able to get most of the settings
done. However I can't find the properties to set the password to
never expire and the user cannot change password. I'd also like to be
able to set the logon hours as well. If someone can help me out with
those properties in VB I would appreciate it. Thanks a lot!
 
J

Jani Järvinen [MVP]

Hi there,
However I can't find the properties to set the password to
never expire and the user cannot change password.

I don't have ready-made VB.NET code for you, but here are some examples
using native Visual Basic:

http://msdn2.microsoft.com/en-us/library/aa705921.aspx

If you can get the property "userAccountControl" of your user object, then
you should be able to change the settings you are after. The value is a flag
value, and here are (in C#) the possible flag values:

public enum ADS_UF_ENUM
{
ADS_UF_SCRIPT = 0X0001,
ADS_UF_ACCOUNTDISABLE = 0X0002,
ADS_UF_HOMEDIR_REQUIRED = 0X0008,
ADS_UF_LOCKOUT = 0X0010,
ADS_UF_PASSWD_NOTREQD = 0X0020,
ADS_UF_PASSWD_CANT_CHANGE = 0X0040,
ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = 0X0080,
ADS_UF_TEMP_DUPLICATE_ACCOUNT = 0X0100,
ADS_UF_NORMAL_ACCOUNT = 0X0200,
ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = 0X0800,
ADS_UF_WORKSTATION_TRUST_ACCOUNT = 0X1000,
ADS_UF_SERVER_TRUST_ACCOUNT = 0X2000,
ADS_UF_DONT_EXPIRE_PASSWD = 0X10000,
ADS_UF_MNS_LOGON_ACCOUNT = 0X20000,
ADS_UF_SMARTCARD_REQUIRED = 0X40000,
ADS_UF_TRUSTED_FOR_DELEGATION = 0X80000,
ADS_UF_NOT_DELEGATED = 0X100000,
ADS_UF_USE_DES_KEY_ONLY = 0x200000,
ADS_UF_DONT_REQUIRE_PREAUTH = 0x400000,
ADS_UF_PASSWORD_EXPIRED = 0x800000,
ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = 0x1000000
};

From these flags, the values ADS_UF_PASSWD_CANT_CHANGE and
ADS_UF_DONT_EXPIRE_PASSWD should be the ones you need. Haven't tested,
though.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top