Alert users to change their password

The following VBS script displays an alert to users at login that the password is soon to expire.

The script

' Days before to alert user 
QtDiasAviso = 7 
RedirectRdWeb = true
UrlRDWEB = "https://monserveur/RDWeb/Pages/fr-FR/password.aspx"
Message_alert = ""
Set oTranslate = CreateObject("NameTranslate") 
Set oNetwork = CreateObject("WScript.Network") 
Set wshell = WScript.CreateObject("WScript.Shell")

oTranslate.Init 3,"" 
oTranslate.Set 3, oNetwork.UserDomain & "\" & oNetwork.UserName 
Set objUserLDAP = GetObject _ 
intCurrentValue = objUserLDAP.Get("userAccountControl") 
' Check if user account have date to password expires 
If not intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then 
    ' Determine when password expires and calculate the days 
    ' Instead of PasswordExpirationDate, you can use the accountExpirationDate property, depending on the case 
    SenhaAlt = DateDiff("d",date,objUserLDAP.PasswordExpirationDate) 
    ' If password will expire 
    if (SenhaAlt <= QtDiasAviso) then
    Message_alert = "Votre mot de passe expire dans  " &amp; SenhaAlt &amp; " jour(s) " &amp; vbCrLf &amp; vbCrLf &amp; "Merci de le changer dès que possible"
    if(RedirectRdWeb = true) then
      Message_alert = Message_alert &amp; vbCrLf &amp; vbCrLf &amp; "Une page intranet va s'ouvrir pour vous permettre le changement"
    end if
     MsgBox Message_alert, vbExclamation,"Expiration de votre mot de passe"
    if(RedirectRdWeb = true) then
      wshell.Run UrlRDWEB
    end if
    end if 
end if


Customizing the script

line 2 :

QtDiasAviso = 7

Number of days the message begins to appear

line 3 :

RedirectRdWeb = true

True : opens the page defined in the UrlRDWEB variable when the user clicks OK

False : Close the window when the user click OK

line 4 :

UrlRDWEB = "https://monserveur/RDWeb/Pages/fr-FR/password.aspx"

URL of the page where the user can change his password.

line 29,32 :

Customizing the message that is displayed to the user.

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Related Posts

Printer mapping: GPO and Script
When setting up an Active Directory, one of the things you want to set up automatically is the printer mapping to the different users. Before setting up GPOs, you must have shared your printers. As for mapping network drives, I'll introduce you to tw

How to deploy an RDS Farm Windows 2012R2/2016/2019
In this tutorial, we will see how to set up a RDS farm in Windows 2012R2 / 2016/2019 with the following features: Remote Desktop Session Host (x2)Service broker for the distribution of connectionsSetting up a collectionPublishing RemoteApp on a web p

Publish RemoteApp 2008R2 on a Farm RDS 2012R2 / 2016/2019
Presentation In this article, I will explain how to publish RemoteApp applications from an RDS server running Windows 2008R2 on a RDS 2012,2016 or 2016 farm. Prerequisites An RDS server running Windows 2008R2 with published RemoteApp applications.An