Discussion:
pwdLastSet property setting problem with C#
(too old to reply)
Tigran Martirosyan
2004-05-24 10:26:01 UTC
Permalink
Hi everyone
I have a problem to setting pwdLastSet property in 0, for making new user change password on next logon
My code sample in C#

DirectoryEntry AD = null
AD = new DirectoryEntry("WinNT://" +di.User_Domain)
DirectoryEntry NewUser = AD.Children.Add(di.User_Login, "user")
NewUser.Invoke("SetPassword", new object[] {di.User_Password})
NewUser.Invoke("Put", new object[] {"Description", di.User_Description})
NewUser.Invoke("Put", new object[] {"FullName", di.User_FullName})
NewUser.CommitChanges()

long v = 0
NewUser.Properties["pwdLastSet"].Add(v); // This line send exception!
NewUser.CommitChanges()
How can I resolve this problem
Thanks.
Marc Scheuner [MVP ADSI]
2004-05-24 14:56:39 UTC
Permalink
I have a problem to setting pwdLastSet property in 0, for making new user change password on next logon.
Your problem is that you're mixing attributes from the WinNT and the
LDAP provider ! The "pwdLastSet" is ONLY accessible if you use the
LDAP provider.

My recommendation would be to use LDAP:// exclusively - dump the WinNT
stuff, it's obsolete, and only there for backwards compatibility.

DirectoryEntry AD = new
DirectoryEntry("LDAP://cn=Users,dc=fabrikam,dc=com");

DirectoryEntry NewUser = AD.Children.Add("cn=" + di.User_Login,
"user");

// this can be done MUCH easier!!!!!
// NewUser.Invoke("Put", new object[] {"Description",
// di.User_Description});

NewUser.Properties["description"].Value = di.User_Description;
NewUser.Properties["displayName"].Value = di.User_FullName;
NewUser.CommitChanges();

// don't call SetPassword until you've committed the changes
// to the directory store at least once!!
NewUser.Invoke("SetPassword", new object[] {di.User_Password});

// now set the pwdLastSet attribute
long v = 0;
NewUser.Properties["pwdLastSet"].Value = v;
NewUser.CommitChanges();

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch

Loading...