• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

windows 7 password expiration popup

Hi,

I'm sorry if this a trivial question.  I've been trying to get this scrip to work on my domain so users get a popup when network passwords are about to expire on windows 7 machines.  Do I have to change anything on this script?

I've been changing GetObject("LDAP://" to fit my domain so I've put either

LDAP://CN=Users, DC=mydomain, dc=com  or
LDAP://DC=mydomain, dc=com

but in either case I get an error.  The only time i don't get an error is when I leave it alone "LDAP://"  but then nothing happens.  I've tried to look on the web but I can't find people saying they are modifying it.

I'm missing something stupid I know.  Sorry new to scripting.
Here is the script:

'==========================================
' Check for password expiring notification
'==========================================
' First, get the domain policy.
'==========================================
Dim oDomain
Dim oUser
Dim maxPwdAge
Dim numDays
Dim warningDays
warningDays = 26
   
Set LoginInfo = CreateObject("ADSystemInfo")  
Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")  
strDomainDN = UCase(LoginInfo.DomainDNSName)
strUserDN = LoginInfo.UserName
'========================================
' Check if password is non-expiring.
'========================================
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
intUserAccountControl = objUser.Get("userAccountControl")
If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
'WScript.Echo "The password does not expire."
Else

Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")
'========================================
' Calculate the number of days that are
' held in this value.
'========================================
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
maxPwdAge.LowPart) / CCur(-864000000000)
'WScript.Echo "Maximum Password Age: " & numDays

'========================================
' Determine the last time that the user
' changed his or her password.
'========================================
Set oUser = GetObject("LDAP://" & strUserDN)
'========================================
' Add the number of days to the last time
' the password was set.
'========================================
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
fromDate = Date
daysLeft = DateDiff("d",fromDate,whenPasswordExpires)

'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged
if (daysLeft < warningDays) and (daysLeft > -1) then
Msgbox "Your password will expire in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Press CTRL + ALT + DEL and select the 'Change a password' option.", 0, "Password Expiration Warning"
End if
End if
'========================================
' Clean up.
'========================================
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing
0
ozzalot
Asked:
ozzalot
1 Solution
 
Joshua GrantomSenior EngineerCommented:
You shouldnt have to change anything. this is a variable & LoginInfo.UserName & that should return the correct info
'========================================
' First, get the domain policy.
'========================================
Dim oDomain
Dim oUser
Dim maxPwdAge
Dim numDays
Dim warningDays

warningDays = 6

Set LoginInfo = CreateObject("ADSystemInfo")  
Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")  
strDomainDN = UCase(LoginInfo.DomainDNSName) 
strUserDN = LoginInfo.UserName


Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")

'========================================
' Calculate the number of days that are
' held in this value.
'========================================
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
                maxPwdAge.LowPart) / CCur(-864000000000)
'WScript.Echo "Maximum Password Age: " & numDays

'========================================
' Determine the last time that the user
' changed his or her password.
'========================================
Set oUser = GetObject("LDAP://" & strUserDN)

'========================================
' Add the number of days to the last time
' the password was set.
'========================================
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
fromDate = Date
daysLeft = DateDiff("d",fromDate,whenPasswordExpires)

'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged

if (daysLeft < warningDays) and (daysLeft > -1) then
    Msgbox "Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Once logged in, press CTRL-ALT-DEL and" & chr(13) & "select the 'Change a password' option", 0, "PASSWORD EXPIRATION WARNING!"
End if

'========================================
' Clean up.
'========================================
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing

Open in new window

0
 
Natty GregIn Theory (IT)Commented:
Thats a lot of work, if you have a Domain controller you should set it up the policy and deploy it to all user, and whalla everyone is reminded. If no DC you can setup the same policy in the Win 7 machine and then, force it to all computers on the network.
0
 
McKnifeCommented:
I use this short batchcode inside the logon script:

net user %username% /domain|findstr /C:"Password expires" >%temp%\expiry.txt
for /f "tokens=3" %%a in (%temp%\expiry.txt) do set expirydate=%%a
echo %date% >%temp%\today.txt
for /f "tokens=2" %%a in (%temp%\today.txt) do set today=%%a
if %today%==%expirydate% msg %username% Your passwords expires today!

Open in new window

0
 
ozzalotAuthor Commented:
Not sure what happened.  I ran the script as is and it worked.  Brain fart i guess after trying to get it to work all day.  I'm pushing via GPO this will work great
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now