Setting "User must change password at next logon"

Setting "User must change password at next logon"

Post by MS Newsgroup » Thu, 24 Apr 2003 16:58:29



Hi,

Does anyone know how to set the "User must change password at next logon"
property when creating a new user object in VB .Net ? I have found some
earlier posts about this, but no working solution. Below is my code which
works fine with the exception of that the account does not have the "Must
change..." property set if someone knows how to do this, please let me know

All help appreciated

Regards

Niclas Lindblom

Sub CreateUser(ByVal FirstName As String, ByVal Lastname As String)

Dim sOU As String =
System.Configuration.ConfigurationSettings.AppSettings.Get("sOU")
Dim sSamAccountName As String = Left(Lastname, 7) & Left(Lastname, 1)
Dim dirEntry As New DirectoryEntry("LDAP://" & sOU)
Dim newUser As DirectoryEntry
newUser = dirEntry.Children.Add("CN=Test", "User")
newUser.Properties("sAMAccountName").Add(sSamAccountName)
newUser.CommitChanges()

With newUser
.Properties("userPrincipalName").Add(sSamAccountName)
.Properties("UserAccountControl").Value = 512
.Properties("pwdLastSet").Value = -1
.Invoke("SetPassword", New Object() {"MyPass"})
.CommitChanges()
End With

End Sub

 
 
 

Setting "User must change password at next logon"

Post by Richard Muelle » Thu, 24 Apr 2003 23:38:29


Hi,

If you set pwdLastSet to -1, that means the user does NOT
have to change their password. To force them to change
their password the next time they logon, set pwdLastSet to
0 (zero).

Richard
http://www.rlmueller.net

Quote:>-----Original Message-----
>Hi,

>Does anyone know how to set the "User must change

password at next logon"
Quote:>property when creating a new user object in VB .Net ? I
have found some
>earlier posts about this, but no working solution. Below
is my code which
>works fine with the exception of that the account does
not have the "Must
>change..." property set if someone knows how to do this,
please let me know

>All help appreciated

>Regards

>Niclas Lindblom

>Sub CreateUser(ByVal FirstName As String, ByVal Lastname
As String)

>Dim sOU As String =
>System.Configuration.ConfigurationSettings.AppSettings.Get
("sOU")
>Dim sSamAccountName As String = Left(Lastname, 7) & Left
(Lastname, 1)
>Dim dirEntry As New DirectoryEntry("LDAP://" & sOU)
>Dim newUser As DirectoryEntry
>newUser = dirEntry.Children.Add("CN=Test", "User")
>newUser.Properties("sAMAccountName").Add(sSamAccountName)
>newUser.CommitChanges()

>With newUser
>..Properties("userPrincipalName").Add(sSamAccountName)
>..Properties("UserAccountControl").Value = 512
>..Properties("pwdLastSet").Value = -1
>..Invoke("SetPassword", New Object() {"MyPass"})
>..CommitChanges()
>End With

>End Sub

>.


 
 
 

Setting "User must change password at next logon"

Post by MS Newsgroup » Fri, 25 Apr 2003 20:12:25


Thanks !

Niclas


Quote:> Hi,

> If you set pwdLastSet to -1, that means the user does NOT
> have to change their password. To force them to change
> their password the next time they logon, set pwdLastSet to
> 0 (zero).

> Richard
> http://www.rlmueller.net
> >-----Original Message-----
> >Hi,

> >Does anyone know how to set the "User must change
> password at next logon"
> >property when creating a new user object in VB .Net ? I
> have found some
> >earlier posts about this, but no working solution. Below
> is my code which
> >works fine with the exception of that the account does
> not have the "Must
> >change..." property set if someone knows how to do this,
> please let me know

> >All help appreciated

> >Regards

> >Niclas Lindblom

> >Sub CreateUser(ByVal FirstName As String, ByVal Lastname
> As String)

> >Dim sOU As String =
> >System.Configuration.ConfigurationSettings.AppSettings.Get
> ("sOU")
> >Dim sSamAccountName As String = Left(Lastname, 7) & Left
> (Lastname, 1)
> >Dim dirEntry As New DirectoryEntry("LDAP://" & sOU)
> >Dim newUser As DirectoryEntry
> >newUser = dirEntry.Children.Add("CN=Test", "User")
> >newUser.Properties("sAMAccountName").Add(sSamAccountName)
> >newUser.CommitChanges()

> >With newUser
> >..Properties("userPrincipalName").Add(sSamAccountName)
> >..Properties("UserAccountControl").Value = 512
> >..Properties("pwdLastSet").Value = -1
> >..Invoke("SetPassword", New Object() {"MyPass"})
> >..CommitChanges()
> >End With

> >End Sub

> >.

 
 
 

1. Using ADSI to set "User must change password at next logon"

Hi,

I'm writing a script to force all user accounts in our domain to change
their password at the next logon.  However this attribute doesn't seem to
exist in the list of user flags I've seen in the ADS_USER_FLAG_ENUM
documentation on Microsoft's MSDN site.  I thought that I might be able to
use UF_NORMAL_ACCOUNT but that doesn't seem to work.  Does anyone know how I
might be able to set that flag?  Thanks for any help offered.

Sincerely,

David Shriner

2. ftp and IPfilters

3. changing default share "users" to "users$"

4. Emacs rmail / HP95 freemacs rmail

5. Changing User Password when set to Change at next logon

6. Mixing Alphas and PCs on KVM switch

7. Set "User Cant Change Password" flag with Visual Basic?

8. Dialog problems

9. How to set "User Cannot Change Password" flag

10. Setting "User Must Change Password" flag

11. Changing a user password who has 'Change Password at next Logon' flagged

12. Modifying A User "Password" "Deleting"

13. How to check the "Allow Access" box, set the "User Logon Name", & "Password Never Expires"