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:

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

Let us improve this post!

Related Posts

How to deploy a rds farm Windows 2012R2/2016/2019
In this article, I will explain the step-by-step roll-out of a Windows 2012 R2 / 2016 RDS farm with the following features: Remote Desktop Session Host (x2) Service broker for distribution of connections Setting up a collection; Publishing RemoteApp

HTML5 client for Microsoft Remote Desktop Service
"Finally an HTML5 client for Windows RDS farms" Presentation In this tutorial, I explain how to set up the HTML 5 client interface to connect to the RDS farm on Windows. Until now to connect to Remote Desktop or RemoteApp, it was necessary to have a

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