Setting "User must change password at next logon"

Setting "User must change password at next logon"

Post by RVN0ZWl » Thu, 10 Mar 2005 05:57:02


I am creating an application in VB.Net to reset passwords for users. I am
able to reset the password succesfully but I can not set the option for "User
must change password at next logon". Listed is the code that I am using to
reset the password as well as the code that I have been able to find for
checking the "User must change password at next logon. This method does not
return any errors, however the flag is not set on the account.

loSearchResult.GetDirectoryEntry().Invoke("SetPassword", New Object()
{Me.txtPassword.Value.ToString()})
loSearchResult.GetDirectoryEntry().CommitChanges()
loSearchResult.GetDirectoryEntry().Properties("pwdLastSet").Add(0)
loSearchResult.GetDirectoryEntry().CommitChanges()

Any suggestions or comments would be appreciated.
 
 
 

Setting "User must change password at next logon"

Post by Marc Scheu » Thu, 10 Mar 2005 16:24:40


Try to set the .Value property instead of adding another value to the
"pwdLastSet" attribute:


Try

loSearchResult.GetDirectoryEntry().Properties("pwdLastSet").Value = 0;

What you're doing is adding another value to a potentially
multi-valued property - you'll have several values in that attribute
now.

By setting it using .Value = 0, you're setting it to just one single
value of 0 (zero).

Marc
________________________________________________________________
Marc Scheuner ** mscheuner -at- mvps.org ** http://www.yqcomputer.com/
Microsoft MVP for Directory Services Programming
http://www.yqcomputer.com/
http://www.yqcomputer.com/

 
 
 

Setting "User must change password at next logon"

Post by RVN0ZWl » Fri, 11 Mar 2005 00:27:05

I tried it using .value instead of .add and it still doesn't work. I can get
it to work just fine using vbscript but when I put it into VB.Net it does
nothing. Any help would be appreciated.
 
 
 

Setting "User must change password at next logon"

Post by Lutz Ele » Fri, 11 Mar 2005 03:26:59


Property UserMustChangePasswordAtNextLogon() As Boolean
Get
Return CType(getProperty("PasswordExpired"), Int32) = 1
End Get
Set(ByVal Value As Boolean)
If Value Then
setProperty("PasswordExpired", 1)
Else
setProperty("PasswordExpired", 0)
End If
End Set
End Property



Sub SetProperty(ByVal name As String, ByVal args As Object)
Dim n As Object = d.NativeObject ' d = DirectoryEntry
Dim o() As Object = {args}
n.GetType.InvokeMember(name,
Reflection.BindingFlags.SetProperty, Nothing, n, o)
d.CommitChanges()
End Sub
 
 
 

Setting "User must change password at next logon"

Post by RVN0ZWl » Fri, 11 Mar 2005 11:27:03

Thank you Lutz.

Replacing SetProperty("PasswordExpired", 1) with SetProperty("pwdLastSet",
0) did the trick.
 
 
 

Setting "User must change password at next logon"

Post by MVP - AD » Fri, 11 Mar 2005 15:22:56

I was able to get this to work by using:

loSearchResult.GetDirectoryEntry().Properties("pwdLastSet").Value = 0

It seems more straightforward than using some kind of late bound reflection
approach.

Joe K.
 
 
 

Setting "User must change password at next logon"

Post by MVP - AD » Fri, 11 Mar 2005 15:24:52

Ah, one other thing. Don't call GetDirectoryEntry over and over. It
creates a new object every time. You should set the result of
GetDirectoryEntry to a DirectoryEntry variable and use that for the rest of
your modifications.

Joe K.