如何让用户密码在快过期时Word文档格式.docx
- 文档编号:5137797
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:11
- 大小:18.83KB
如何让用户密码在快过期时Word文档格式.docx
《如何让用户密码在快过期时Word文档格式.docx》由会员分享,可在线阅读,更多相关《如何让用户密码在快过期时Word文档格式.docx(11页珍藏版)》请在冰点文库上搜索。
conststrSMTPServer="
mailserver"
寄信ExchangeServer
conststrSendUserName="
domainname\ACCOUNT"
有權限的使用者(寄信使用)
conststrSendPassword
="
PASSWORD"
密碼
conststrFullAdsiPath="
LDAP:
//DC
LDAP路徑
arrWillExpiredDays=Array(15,7,3,2,1)
將要過期天數的陣列
MainFunction
Declarevariables
DimstrTestMode
strTestMode=False
'
usefordebuging
Cretaelogfile
SetWshSHell=CreateObject("
Wscript.Shell"
)
SetobjFSO=CreateObject("
Scripting.FileSystemObject"
strFileName=Replace(Datevalue(Now),"
-"
"
_"
strFileName=Replace(strFileName,"
/"
PublicfLog
SetoLog=objFSO.OpenTextFile(strFileName&
"
.txt"
ForWriting,TRUE)
PrintScreenNow
PrintScreen"
"
sta=ListWillExpireUsers()
PrintScreensta
Thecommandrunssuccessfully!
oLog.Close
Programending
wscript.quit
======================================
FunctionArea
*Function:
PrintScreen
*Purpose:
ShowMessage
*Input:
Message
*
*Output:
None
SubPrintScreen(strMessage)
ifstrTestMode=Truethen
Wscript.EchostrMessage
endif
oLog.WriteLinestrMessage
EndSub
*FunctionListWillExpireUsers(nDays)
*Listalluserobjectswhosepasswordwillbeexpiredorisexpired
*nDays:
howmanydaysthepasswordwillbeexpired
*-------------------------------------------------------------------
FunctionListWillExpireUsers()
DimstrMailAddress
CreateUserObject
SetobjConnection=CreateObject("
ADODB.Connection"
SetobjCommand=CreateObject("
ADODB.Command"
objConnection.Provider="
ADsDSOObject"
objConnection.Open"
ActiveDirectoryProvider"
SetobjCommand.ActiveConnection=objConnection
objCommand.CommandText="
<
&
strFullAdsiPath&
>
;
(&
(objectCategory=person)(objectclass=user));
AdsPath,cn;
subTree"
objCommand.Properties("
PageSize"
)=99
specifiesthemaximumnumberofobjectstoreturninaresultsset.
PrintScreenobjCommand.CommandText
SetobjRecordSet=objCommand.Execute
IfobjRecordSet.RecordCount=0Then
Error:
Cannotfoundtheuserobjectindomain"
BaseDN&
."
Else
DimintTotalAccount
計算找到幾位使用者
intTotalAccount=0
objRecordSet.MoveFirst
DoUntilobjRecordSet.EOF
intTotalAccount=intTotalAccount+1
Retriveuserinformation
DimoUser
SetoUser=GetObject(objRecordSet.Fields("
ADsPath"
).Value)
ForEachoUserPropertyinoUser
PrintScreenoUserProperty.Name
Next
If(oUser.AccountDisabled=FALSE)Then
PrintScreenvbTab&
UserName:
oUser.Name
sStatus=UserPwdExpire(oUser)
SelectCasesStatus
Case999999
Theuser"
oUser.samaccountname&
Passwordneverexpires."
CaseElse
ifsStatus>
=0then
strMSG="
Yourpasswordisalreadyexpiredin"
sStatus&
days!
oUser.samAccountName&
passwordisexpiredafter"
elseifsStatus<
0then
Yourmailaccountpasswordwillbeexpiredin"
0-sStatus&
vbcrlf&
Pleasechangeyourpasswordassoonas!
passwordwillbeexpiredin"
endif
ForeachcheckDaysinarrWillExpiredDays
ifcheckDays=(0-sStatus)then
callfnCheck_SendMail(oUser,strMSG)
next
EndSelect
else
AccountDisabled."
objRecordSet.MoveNext
Loop
EndIf
TotalAccountsis"
intTotalAccount
ListWillExpireUsers="
OK"
EndFunction
*FunctionUserPwdExpire(objUser,nMaxPwdAge)
*Checkifuserobjectpasswordisorwillbeexpired
*objUser:
theuserobject
nMaxPwdAge:
maximumpasswordageofdomain
FunctionUserPwdExpire(objUser)
OnErrorResumeNext
ConstADS_UF_DONT_EXPIRE_PASSWD
=&
H10000
ConstSEC_IN_DAY=86400
intCurrentValue=objUser.Get("
userAccountControl"
IfintCurrentValueandADS_UF_DONT_EXPIRE_PASSWDThen
Thepassworddoesnotexpire.
UserPwdExpire=999999'
永遠不過期
dtmValue=objUser.PasswordLastChanged
iferr.number<
dtmValue=0
err.Clear
Thepasswordwaslastchangedon"
DateValue(dtmValue)&
at"
TimeValue(dtmValue)
Thepasswordwaslastchangedon"
_
DateValue(dtmValue)&
TimeValue(dtmValue)&
VbCrLf&
Thedifferencebetweenwhenthepasswordwaslastset"
andtodayis"
int(now-dtmValue)&
days"
intTimeInterval=int(now-dtmValue)
SetobjSysInfo=CreateObject("
ADSystemInfo"
strDomain=objSysInfo.DomainShortName
SetobjSysInfo=Nothing
SetobjDomainNT=GetObject("
WinNT:
//"
strDomain)
intMaxPwdAge=objDomainNT.Get("
MaxPasswordAge"
IfintMaxPwdAge<
0Then
WScript.Echo"
TheMaximumPasswordAgeissetto0inthe"
domain.Therefore,thepassworddoesnotexpire."
intMaxPwdAge=(intMaxPwdAge/SEC_IN_DAY)
Wscript.echo"
Themaximumpasswordageis"
intMaxPwdAge&
IfintTimeInterval>
=intMaxPwdAgeThen
Thepasswordhasexpired."
UserPwdExpire=int(intTimeInterval-intMaxPwdAge)
Thepasswordwillexpireon"
DateValue(dtmValue+intMaxPwdAge)&
("
int((dtmValue+intMaxPwdAge)-now)&
daysfromtoday"
)."
UserPwdExpire=int(now-(dtmValue+intMaxPwdAge))
******************************
MailMessage
Reference:
CreatingandSendingaMessage
SubSendMail(strFrom,strTo,strSubject,strBodyText)
DimiMsg
SetiMsg=CreateObject("
CDO.Message"
DimiConf
SetiConf=CreateObject("
CDO.Configuration"
DimFlds
SetFlds=iConf.Fields
WithFlds
assumeconstantsaredefinedwithinscriptfile
.Item("
cdoSendUsingMethod"
)=2
cdoSendUsingPickup:
1:
Local,cdoSendUsingPort:
2:
Network
cdoSendUsingPort"
)
=25
cdoSendUsingPort
cdoSMTPServer"
=strSMTPServer
cdoSMTPConnectionTimeout"
)=10
quicktimeout
cdoSMTPAuthenticate"
)=cdoBasic
cdoSendUserName"
=strSendUserName
cdoSendPassword"
=strSendPassword
.Item("
cdoURLProxyServer"
tpeproxy:
80"
cdoURLProxyBypass"
local>
cdoURLGetLatestVersion"
=True
.Update
EndWith
WithiMsg
Set.Configuration=iConf
.To
=strTo
.From
=strFrom
.Subject
=strSubject
.CreateMHTMLBody"
Thisfolder["
strFolderPath&
]Createdin"
intDayNum&
Days"
.TextBody=
strBodyText
.AddAttachment"
C:
\files\mybook.doc"
.Send
fnCheck_SendMail
檢查是否有符合寄信標準的使用者(以arrWillExpiredDays為準)
objUser,MailMessage
FunctionfnCheck_SendMail(objUser,strMSG)
Sendemail
Err.Clear
某些User在此行發生Error
DimPropArray
PropArray=Array("
proxyAddresses"
oUser.GetInfoExArray("
),0
aProxyAddress=objUser.GetEx("
IfErr<
0Then
Time&
Theuserdoesn'
thaveemailaddress."
ForEachsaProxyAddressinaProxyAddress
NeedastringvariabletotransferthesaProxyAddress
strMailAddress=saProxyAddress
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 如何 用户密码 过期
![提示](https://static.bingdoc.com/images/bang_tan.gif)