1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Sub bouton12_Quandclic()
'========================================
' First, get the domain policy.
'========================================
'Dim oDomain As IADsContainer
'Dim oUser As IADsUser
Dim maxPwdAge As LargeInteger
'========================================
' Declaring numDays as Currency, due to a
' large number calculation.
'========================================
Dim numDays As Currency
Dim sQuery As String
Set oRoot = GetObject("LDAP://RootDSE")
sDomain = oRoot.Get("defaultNamingContext")
Set conn = CreateObject("ADODB.Connection")
Set comm = CreateObject("ADODB.Command")
conn.Provider = "ADsDSOObject"
conn.Open "ADs Provider"
Set comm.ActiveConnection = conn
strDomainDN = oRoot.Get("defaultNamingContext")
Set oDomainDN = GetObject("LDAP://" & strDomainDN)
sBase = "<" & oDomainDN.ADsPath & ">"
'strUserDN = strDomainDN & "/CN=Administrateur,CN=User,DC=cermex,DC=fr"
sFilter = "(&(objectCategory=person)(objectClass=user)(name=julie))"
sAttribs = "adsPath"
sDepth = "subTree"
sQuery = strDomainDN & ";" & sFilter & ";" & sAttribs & ";" & sDepth
comm.CommandText = sQuery
Set strUserDN = conn.Execute(sQuery)
Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")
'========================================
' Calculate the number of days that are
' held in this value.
'========================================
numDays = ((maxPwdAge.HighPart * 2 ^ 32) + _
maxPwdAge.LowPart) / -864000000000@
Debug.Print "Maximum Password Age: " & numDays
'========================================
' Determine the last time that the user
' changed his or her password.
'========================================
Set oUser = GetObject("LDAP://" & strUserDN) ' erreur sur cette ligne, erreur d automation
'========================================
' Add the number of days to the last time
' the password was set.
'========================================
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
Debug.Print "Password Last Changed: " & oUser.PasswordLastChanged
Debug.Print "Password Expires On: " & whenPasswordExpires
'========================================
' Clean up.
'========================================
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing
End Sub |
Partager