Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Password Expire and Age

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,61087
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Password Expire and Age
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Password Expire and Age - 6/5/2008 6:12:42 AM   
  jcarver_14

 

Posts: 25
Score: 0
Joined: 6/4/2008
From: Cincinnati
Status: offline
Option Explicit
Dim objCommand, objConnection, objChild, objUserConnection, strBase, strFilter, strAttributes, strPasswordChangeDate, intPassAge, intdaystoexpiration
Dim lngTZBias, objPwdLastSet, strEmailAddress, objMessage
Dim objShell, lngBiasKey, k, PasswordExpiry, strRootDomain
Dim strQuery, objRecordset, strName, strCN
' ********************* CHANGE THESE VALUES TO PASSWORD EXPIRY AND ROOT OF WHERE USERS WILL BE SEARCHED ***********************************
PasswordExpiry=###
strRootDomain="dc=domain,dc=com"
' *****************************************************************************************************************************************

' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngTZBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
  lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://" & strRootDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
'(!userAccountControl:1.2.840.113556.1.4.803:=2)(!userAccountControl:1.2.840.113556.1.4.803:=65536))"
strAttributes = "sAMAccountName,cn,mail,pwdLastSet,distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
strName=inputbox("Enter Username to check when password was changed.", "Password Check")
Do Until objRecordSet.EOF
  If objRecordSet.Fields("sAMAccountName").Value = strName Then
      Set objUserConnection = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
      Set objPwdLastSet = objUserConnection.pwdLastSet
      strPasswordChangeDate = Integer8Date(objPwdLastSet, lngTZBias)
      intPassAge = DateDiff("d", strPasswordChangeDate, Now)
intdaystoexpiration = (PasswordExpiry - intPassAge)
      WScript.Echo "Password changed " & intPassAge & " days ago"
WScript.Echo "Password expires in " & intdaystoexpiration & " days. "
  End If
objRecordSet.MoveNext
Loop
objConnection.Close

Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
' Account for error in IADslargeInteger property methods.
If lngLow < 0 Then
  lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
  lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
' Trap error if lngDate is overly large
On Error Resume Next
Integer8Date = CDate(lngDate)
If Err.Number <> 0 Then
  On Error GoTo 0
  Integer8Date = #1/1/1601#
End If
On Error GoTo 0
End Function

< Message edited by jcarver_14 -- 6/5/2008 6:30:41 AM >
 
 
Revisions: 1 | Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Password Expire and Age Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts