首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

操作系统

Windows 9X | Linux&Uinx | Windows Server | 其它操作系统 | Vista | FreeBSD | Windows 7 |
首页 > 操作系统 > Windows Server > 如何让用户密码在快过期时,发邮件提醒用户更改密码 > 正文

如何让用户密码在快过期时,发邮件提醒用户更改密码

出处:5DMail.Net收集整理 作者:5DMail.Net收集整理 时间:2011-1-11 16:20:12

      大家都知道,在域环境中,组策略中可以设置当用户密码快过期时,电脑登录会有提示,但当用户出差,或是用OWA方式访问时,并不会收到相关提示,而导致道密码过期而无法收发邮件!

       下面的方法,就是教大家,如何让用户密码在快过期时,发邮件提醒用户更改密码,让用户去OWA中去更改自已的密码,不至于发生密码过期,用户并不知道,而无法收发邮件!

以下是在AD、Exchange环境下,用邮件的方式通知用户密码到期提示的脚本,需要使用的,请将其路的Domainname.com和Domain改成你的域名,ADserver/Mailserver改为你的AD和Exchange的机器名,然后COPY下面的脚本存为.vbs格式,放在DC中,设置Scheduled Tasks,让其每天在固定时间执行!

注:此脚本文件会和组策略中的密码策略相对应!

此脚本为微软工程师专为某企业而写的,在些对其表示感谢!

'********************************************************************
'* Main Function: 從AD中比對每一個使用者的Password LastSet,如果距離過期日剩30,15,3,2,1的使用者,則發信通知
'*
'* Usage: 
'   For Example : cscript QuerryAD.vbs
'*
'* Copyright (C) 2004 Microsoft Corporation
'********************************************************************
'Option Explicit

'For FileSystemObject
Const ForReading = 1
Const ForAppending = 8
Const ForWriting = 2
Const ADS_PROPERTY_DELETE = 4 

dim arrWillExpiredDays

'Please modify the variable
CONST MASTERMAIL = "administrator@domainname.com"          '寄信人的Email Address
'const strSMTPServer = "mailserver"              '寄信ExchangeServer 
'const strSendUserName = "domainname\ACCOUNT"         '有權限的使用者(寄信使用)
'const strSendPassword  = "PASSWORD"             '密碼
const strFullAdsiPath = "LDAP://DCserver.domainname.com/dc=domainname,dc=com"   'LDAP路徑
arrWillExpiredDays = Array(15,7,3,2,1)            '將要過期天數的陣列

'Main Function

'Declare variables
Dim strTestMode
strTestMode = False  'use for debuging

'Cretae log file
Set WshSHell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
strFileName = Replace(Datevalue(Now), "-", "_")
strFileName = Replace(strFileName, "/", "_")
 
Public fLog
Set oLog = objFSO.OpenTextFile(strFileName & ".txt", ForWriting, TRUE)

PrintScreen Now
PrintScreen ""
 
sta = ListWillExpireUsers()

PrintScreen sta

PrintScreen ""
PrintScreen "The command runs successfully!"
PrintScreen Now
 
oLog.Close


'Program ending
wscript.quit

'======================================
' Function Area  
'======================================

'********************************************************************
'*
'* Function: PrintScreen
'* Purpose:  Show Message
'* Input:    Message
'*           
'* Output:   None
'*
'********************************************************************
Sub PrintScreen(strMessage)
 if strTestMode = True then
  Wscript.Echo strMessage
 end if
 oLog.WriteLine strMessage
End Sub

'********************************************************************
'*Function ListWillExpireUsers(nDays)
'* List all user objects whose password will be expired or is expired
'* nDays: how many days the password will be expired
'*
'*
'*
'*-------------------------------------------------------------------
 
Function ListWillExpireUsers()
 
 Dim strMailAddress
  
 ' Create User Object
 
 Set objConnection = CreateObject("ADODB.Connection")
 Set objCommand = CreateObject("ADODB.Command")
 objConnection.Provider = "ADsDSOObject"
 objConnection.Open "Active Directory Provider"
 Set objCommand.ActiveConnection = objConnection
      
 
 objCommand.CommandText = "<" & strFullAdsiPath & ">;(&(objectCategory=person)(objectclass=user));AdsPath,cn;subTree"
 
 objCommand.Properties("Page Size") = 99  'specifies the maximum number of objects to return in a results set.
 
 
 PrintScreen objCommand.CommandText 
 
 PrintScreen "  "
   
 
 Set objRecordSet = objCommand.Execute
 
 
 If objRecordSet.RecordCount = 0 Then
 
  PrintScreen "Error: Cannot found the user object in domain " & BaseDN & "."
 Else
 
 Dim intTotalAccount '計算找到幾位使用者
 intTotalAccount = 0
 
 
 objRecordSet.MoveFirst
 
 
 Do Until objRecordSet.EOF 
 
  intTotalAccount = intTotalAccount +1
  'Retrive user information
  Dim oUser   
 
    
 
  Set oUser = GetObject(objRecordSet.Fields("ADsPath").Value)
  
  For Each oUserProperty in oUser
   PrintScreen oUserProperty.Name   
 
  Next
    
 
  If (oUser.AccountDisabled = FALSE) Then
    
 
   PrintScreen vbTab & "User Name : " & oUser.Name
   sStatus = UserPwdExpire(oUser)
      
 
   Select Case sStatus

    Case 999999
     PrintScreen vbTab & " The user " & oUser.samaccountname & " Password never expires." 
          
 
    Case Else
     if sStatus >= 0 then  
      strMSG = "Your password is already expired in " & sStatus & " days!"
      PrintScreen vbTab & " The user " & oUser.samAccountName & " password is expired after " & sStatus & " days!" 
     elseif sStatus < 0 then
      strMSG = "Your mail account password will be expired in " & 0-sStatus & " days!" & vbcrlf & "Please change your password as soon as!"
      PrintScreen vbTab & " The user " & oUser.samAccountName & " password will be expired in " & 0-sStatus & " days!"
     end if
 
                
           For each checkDays in arrWillExpiredDays
            if checkDays = (0-sStatus) then
             call fnCheck_SendMail(oUser,strMSG)
 
            end if
           next     
 
   End Select
 
 
 
  else
 
   PrintScreen vbTab & "User Name : " & oUser.Name
   PrintScreen vbTab & " The user " & oUser.samaccountname & " Account Disabled."
 
  end if
     
 
 objRecordSet.MoveNext
 
 
 PrintScreen "  "
  
 
 Loop
 End If
 PrintScreen "Total Accounts is " & intTotalAccount 
 
 
ListWillExpireUsers = "OK"
 
End Function

 

'********************************************************************
'* Function UserPwdExpire(objUser, nMaxPwdAge)
'* Check if user object password is or will be expired
'* objUser: the user object
'*  
'*  nMaxPwdAge: maximum password age of domain
'*
'*-------------------------------------------------------------------
Function UserPwdExpire(objUser)
 
 On Error Resume Next
 Const ADS_UF_DONT_EXPIRE_PASSWD  = &H10000
 
 Const SEC_IN_DAY = 86400
 
 intCurrentValue = objUser.Get("userAccountControl")
 
 If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then
  'The password does not expire.
  UserPwdExpire = 999999 '永遠不過期
 Else
  
  dtmValue = objUser.PasswordLastChanged
 
  if err.number <> 0 then
   dtmValue = 0
   err.Clear
  end if
  
  
  PrintScreen vbTab & " The password was last changed on " & DateValue(dtmValue) & " at " & TimeValue(dtmValue)
  'PrintScreen vbTab & "The password was last changed on " & _
  'DateValue(dtmValue) & " at " & TimeValue(dtmValue) & VbCrLf & _
  ' "The difference between when the password was last set" & VbCrLf & _
  ' "and today is " & int(now - dtmValue) & " days"
  intTimeInterval = int(now - dtmValue)
  
  
  Set objSysInfo = CreateObject("ADSystemInfo")
  strDomain = objSysInfo.DomainShortName
  Set objSysInfo = Nothing
 
 
  Set objDomainNT = GetObject("WinNT://" & strDomain)
  intMaxPwdAge = objDomainNT.Get("MaxPasswordAge")
  
  If intMaxPwdAge < 0 Then
   'WScript.Echo "The Maximum Password Age is set to 0 in the " & _
    '"domain. Therefore, the password does not expire."
  Else
   intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY)
   'Wscript.echo "The maximum password age is " & intMaxPwdAge & " days"
   If intTimeInterval >= intMaxPwdAge Then
    'PrintScreen vbTab &  "The password has expired."
    UserPwdExpire = int(intTimeInterval - intMaxPwdAge)
   Else
    'PrintScreen vbTab &  "The password will expire on " & _
    ' DateValue(dtmValue + intMaxPwdAge) & " (" & _
    ' int((dtmValue + intMaxPwdAge) - now) & " days from today" & ")."
    UserPwdExpire = int(now - (dtmValue + intMaxPwdAge))
 
   End If
  End If
 End If

End Function

  
'******************************
' Mail Message
'Reference : Creating and Sending a Message
'http://msdn.microsoft.com/library/en-us/cdosys/html/_cdosys_messaging_examples_creating_and_sending_a_message.asp?frame=true
'http://msdn.microsoft.com/library/en-us/cdosys/html/_cdosys_cdosendusing_enum.asp?frame=true
'******************************
Sub SendMail(strFrom, strTo, strSubject, strBodyText)
 
 
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")
 
Dim Flds
Set Flds = iConf.Fields
 
With Flds
  ' assume constants are defined within script file
  .Item("cdoSendUsingMethod") = 2       ' cdoSendUsingPickup:1:Local , cdoSendUsingPort:2:Network 
 
  .Item("cdoSendUsingPort")  = 25               'cdoSendUsingPort
  .Item("cdoSMTPServer")  = strSMTPServer
  .Item("cdoSMTPConnectionTimeout") = 10   ' quick timeout
  .Item("cdoSMTPAuthenticate") = cdoBasic
  .Item("cdoSendUserName")  = strSendUserName
  .Item("cdoSendPassword")  = strSendPassword
  '.Item("cdoURLProxyServer")  = "tpeproxy:80"
  .Item("cdoURLProxyBypass")  = "<local>"
  .Item("cdoURLGetLatestVersion")   = True
  .Update
End With
 
With iMsg
   Set .Configuration = iConf
      .To       = strTo
      .From    = strFrom
      .Subject  = strSubject
      '.CreateMHTMLBody "This folder [" & strFolderPath & "] Created in " & intDayNum & " Days"
      .TextBody =  strBodyText
      '.AddAttachment "C:\files\mybook.doc"
      .Send
End With
 
End Sub

 

'********************************************************************
'*
'* Function: fnCheck_SendMail
'* Purpose:  檢查是否有符合寄信標準的使用者(以arrWillExpiredDays為準)
'* Input:    objUser,MailMessage
'*           
'* Output:   None
'*
'********************************************************************
Function fnCheck_SendMail(objUser,strMSG)

 'Send email
 On Error Resume Next
 Err.Clear
  
 '某些User在此行發生Error
 Dim PropArray
  
 'PropArray = Array("proxyAddresses")       
 'oUser.GetInfoEx Array("proxyAddresses"), 0

 aProxyAddress = objUser.GetEx("proxyAddresses")       
  
 If Err<>0 Then
 
  PrintScreen vbTab & Time & " The user doesn't have email address."       
 
  Err.Clear
 Else
  
  For Each saProxyAddress in aProxyAddress
 
   
   'Need a string variable to transfer the saProxyAddress
   strMailAddress = saProxyAddress
   
   ePos = Instr(1,strMailAddress,"SMTP:",VbTextCompare)
   
   'PrintScreen vbTab & vbTab & "ePos = " & ePos        
 
    
   If ePos > 0 Then
 
    
    strEmail = mid(strMailAddress,6)
    PrintScreen vbTab & " Email Address: " & strEmail
     
    'Use Exchange Server to send mail
    'SendMail MASTERMAIL, strEmail, "Password expiration notification!", strMSG
    
    'If server installed the SMTP Service
    SendMessage MASTERMAIL, strEmail, "Password expiration notification!", strMSG
       
    PrintScreen vbTab & " " & Time &  " Finish sending email!"
     
    Exit For
    
   Else        
 
    'PrintScreen vbTab & vbTab & " No SMTP: string"          
 
   End If
   
  Next
  
 End If

end Function

'******************************************************************************
' Send messages with CDO for Windows 2000
' strTo:   [in] To
' strFrom:  [in] From
' strSubject:  [in] Subject
' strBodyFile: [in] Body text file
'******************************************************************************
Sub SendMessage(strFrom, strTo, strSubject, strBodyText) 
 
 ' For more information about CDO for Windows 2000, please refer to
 
 ' 
http://msdn.microsoft.com/library/en-us/exchanchor/htms/msexchsvr_cdowin2000.asp?frame=true
 
 'On Error Resume Next
 Dim oMessage ' as CDO.Message
 Set oMessage = CreateObject("CDO.Message")
 
 oMessage.TextBody = strBodyText
 oMessage.To = strTo
 oMessage.From = strFrom
 oMessage.Subject = strSubject
 Err.Clear
 oMessage.Send 
 
 If Err.number <> 0 then
  Wscript.Echo "Error in SendMessage: id=" & Err.number & ", source=" & Err.Source & ",Desc=" & Err.Description
  Err.Clear
 End If
 Set oMessage = nothing
 
End Sub

相关文章 热门文章
  • 微软推出新功能 提高Hotmail密码安全性
  • 如何通过Exchange2010 OWA更改过期密码
  • 避免AD攻击 防止密码破解和其它常用目录攻击
  • “下次登录时需要更改密码”的用户如何登录OWA 2010
  • ADMT 3.2 迁移密码
  • 我们如何才能防止用户对Web应用程序和共享文件夹使用保存密码的功能呢?
  • 在命令行下修改用户密码
  • 那些带有&@#%^的密码
  • 如何在域环境使用脚本批量更改本地管理员密码
  • 用pspasswd批量修改域内计算机本地管理员密码
  • 企业邮箱密码安全防范,警惕邮箱密码遭窃被非法利用
  • 光纤交换机密码重置
  • “http 500内部服务器错误”的解决方法
  • 利用Windows 2000 Server的RRAS实现VPN服务器
  • 用凤凰万能启动盘解决本地/域管理员密码丢失
  • Win2003 Server企业版安装配置
  • Active directory 灾难恢复
  • Windows 2000/03域和活动目录
  • 如何在vmware4上创建windows 2003群集
  • MSI文件制作全过程
  • Win2000命令全集(一)
  • Windows 2000/AD技巧
  • 此系统的本地策略不允许您采用交互式登录解决方法
  • Win2000路由的安装与设置实现不同网段互通
  • 自由广告区
     
    最新软件下载
  • SharePoint Server 2010 部署文档
  • Exchange 2010 RTM升级至SP1 教程
  • Exchange 2010 OWA下RBAC实现的组功能...
  • Lync Server 2010 Standard Edition 标..
  • Lync Server 2010 Enterprise Edition...
  • Forefront Endpoint Protection 2010 ...
  • Lync Server 2010 Edge 服务器部署文档
  • 《Exchange 2003专家指南》
  • Mastering Hyper-V Deployment
  • Windows Server 2008 R2 Hyper-V
  • Microsoft Lync Server 2010 Unleashed
  • Windows Server 2008 R2 Unleashed
  • 今日邮件技术文章
  • 腾讯,在创新中演绎互联网“进化论”
  • 华科人 张小龙 (中国第二代程序员 QQ...
  • 微软推出新功能 提高Hotmail密码安全性
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算..
  • 国内手机邮箱的现状与未来发展——访尚..
  • 易观数据:2011Q2中国手机邮箱市场收入..
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • Hotmail新功能:“我的朋友可能被黑了”
  • 入侵邻居网络发骚扰邮件 美国男子被重..
  • 网易邮箱莫子睿:《非你莫属》招聘多过..
  • 中国电信推广189邮箱绿色账单
  • 最新专题
  • 鸟哥的Linux私房菜之Mail服务器
  • Exchange Server 2010技术专题
  • Windows 7 技术专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • Apache James 专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2010 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号