Vba VB宏中的pwdLastSet
我得到pwdLastSet属性。我得到应用程序定义或对象定义的错误Vba VB宏中的pwdLastSet,vba,excel,active-directory,Vba,Excel,Active Directory,我得到pwdLastSet属性。我得到应用程序定义或对象定义的错误pwdLastSet是一个64位整数: 对于VB,它是一个具有两个长属性的对象:HighPart和LowPart 你需要什么,从 ”从机器注册表获取本地时区偏差。 “这种偏见随着夏令时的变化而变化。 设置objShell=CreateObject(“Wscript.Shell”) lngBiasKey=objShell.regrad(“HKLM\System\CurrentControlSet\Control\TimeZoneI
pwdLastSet
是一个64位整数:
对于VB,它是一个具有两个长属性的对象:HighPart
和LowPart
你需要什么,从
”从机器注册表获取本地时区偏差。
“这种偏见随着夏令时的变化而变化。
设置objShell=CreateObject(“Wscript.Shell”)
lngBiasKey=objShell.regrad(“HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias”)
如果(UCase(TypeName(lngBiasKey))=“LONG”),则
lngBias=lngBiasKey
ElseIf(UCase(TypeName(lngBiasKey))=“VARIANT()”)然后
lngBias=0
对于k=0到UBound(lngBiasKey)
lngBias=lngBias+(lngBiasKey(k)*256^k)
下一个
如果结束
Set objUser=GetObject(“LDAP://”&strUserDN)
’--这是两条相关的线---
Set objDate=objUser.pwdLastSet
dtmPwdLastSet=整数8Date(objDate,lngBias)
函数Integer8Date(ByVal objDate,ByVal lngBias)
'函数将整数8(64位)值转换为日期,并针对
“本地时区偏差。
朦胧的,朦胧的,朦胧的,朦胧的,朦胧的
lngAdjust=lngBias
lngHigh=objDate.HighPart
lngLow=objdate.LowPart
'解释IADsLargeInteger属性方法中的错误。
如果(lngLow<0),则
lngHigh=lngHigh+1
如果结束
如果(lngHigh=0)和(lngLow=0),则
lngAdjust=0
如果结束
lngDate=#1/1/1601#+((lngHigh*(2^32))_
+lngLow)/600000000-lngAdjust)/1440
“陷阱错误,如果lngDate是荒谬的巨大。
出错时继续下一步
Integer8Date=CDate(lngDate)
如果(错误编号0),则
错误转到0
整数8日期=#1/1/1601#
如果结束
错误转到0
端函数
pwdLastSet
是一个64位整数:
对于VB,它是一个具有两个长属性的对象:HighPart
和LowPart
你需要什么,从
”从机器注册表获取本地时区偏差。
“这种偏见随着夏令时的变化而变化。
设置objShell=CreateObject(“Wscript.Shell”)
lngBiasKey=objShell.regrad(“HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias”)
如果(UCase(TypeName(lngBiasKey))=“LONG”),则
lngBias=lngBiasKey
ElseIf(UCase(TypeName(lngBiasKey))=“VARIANT()”)然后
lngBias=0
对于k=0到UBound(lngBiasKey)
lngBias=lngBias+(lngBiasKey(k)*256^k)
下一个
如果结束
Set objUser=GetObject(“LDAP://”&strUserDN)
’--这是两条相关的线---
Set objDate=objUser.pwdLastSet
dtmPwdLastSet=整数8Date(objDate,lngBias)
函数Integer8Date(ByVal objDate,ByVal lngBias)
'函数将整数8(64位)值转换为日期,并针对
“本地时区偏差。
朦胧的,朦胧的,朦胧的,朦胧的,朦胧的
lngAdjust=lngBias
lngHigh=objDate.HighPart
lngLow=objdate.LowPart
'解释IADsLargeInteger属性方法中的错误。
如果(lngLow<0),则
lngHigh=lngHigh+1
如果结束
如果(lngHigh=0)和(lngLow=0),则
lngAdjust=0
如果结束
lngDate=#1/1/1601#+((lngHigh*(2^32))_
+lngLow)/600000000-lngAdjust)/1440
“陷阱错误,如果lngDate是荒谬的巨大。
出错时继续下一步
Integer8Date=CDate(lngDate)
如果(错误编号0),则
错误转到0
整数8日期=#1/1/1601#
如果结束
错误转到0
端函数
Active Directory中的日期值很奇怪。我如何才能看到哪些属性可用于USER?Active Directory中的日期值很奇怪。我如何才能看到哪些属性可用于USER?
Option Explicit
Const ADS_SCOPE_SUBTREE = 2
Sub LoadUserInfo()
Dim x, objConnection, objCommand, objRecordSet, oUser, skip, disa
Dim sht As Worksheet
' get domain
Dim oRoot
Set oRoot = GetObject("LDAP://rootDSE")
Dim sDomain
sDomain = oRoot.Get("defaultNamingContext")
Dim strLDAP
strLDAP = "LDAP://OU=ExxonExecutives," & sDomain
MsgBox strLDAP
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT adsPath FROM '" & strLDAP & "' WHERE objectCategory='person'AND objectClass='user'"
Set objRecordSet = objCommand.Execute
x = 2
Set sht = ThisWorkbook.Worksheets("Company")
With sht
' Clear and set Header info
.Cells.Clear
.Cells.NumberFormat = "@"
.Cells(1, 1).Value = "Login"
.Cells(1, 2).Value = "Name"
.Cells(1, 3).Value = "Surmane"
.Cells(1, 4).Value = "Display Name"
.Cells(1, 5).Value = "Departement"
.Cells(1, 6).Value = "Title"
.Cells(1, 7).Value = "Telephone"
.Cells(1, 8).Value = "Mobile"
.Cells(1, 9).Value = "Fax"
.Cells(1, 10).Value = "Initials"
.Cells(1, 11).Value = "Company"
.Cells(1, 12).Value = "Address"
.Cells(1, 13).Value = "P.O. box"
.Cells(1, 14).Value = "Zip"
.Cells(1, 15).Value = "Town"
.Cells(1, 16).Value = "State"
.Cells(1, 17).Value = "Manager"
.Cells(1, 18).Value = "Password Last Changed"
Do Until objRecordSet.EOF
Set oUser = GetObject(objRecordSet.Fields("aDSPath"))
skip = oUser.sAMAccountName
disa = oUser.AccountDisabled
If (skip = "Administrator") Or (skip = "Guest") Or (skip = "krbtgt") Or (disa = "True") Then
.Cells(x, 1).Value = "test"
DoEvents
objRecordSet.MoveNext
Else
.Cells(x, 1).Value = CStr(oUser.sAMAccountName) 'Replace(oUser.Name, "CN=", "")
.Cells(x, 2).Value = oUser.givenName
.Cells(x, 3).Value = oUser.SN
.Cells(x, 4).Value = oUser.DisplayName
.Cells(x, 5).Value = oUser.department
.Cells(x, 6).Value = oUser.Title
.Cells(x, 7).Value = oUser.telephoneNumber
.Cells(x, 8).Value = oUser.mobile
.Cells(x, 9).Value = oUser.facsimileTelephoneNumber
.Cells(x, 10).Value = oUser.initials
.Cells(x, 11).Value = oUser.company
.Cells(x, 12).Value = oUser.streetAddress
.Cells(x, 13).Value = oUser.postOfficeBox
.Cells(x, 14).Value = oUser.postalCode
.Cells(x, 15).Value = oUser.l ' by
.Cells(x, 16).Value = oUser.st
.Cells(x, 17).Value = oUser.manager
.Cells(x, 18).Value = oUser.pwdLastSet // CRAAAASH!
DoEvents
x = x + 1
objRecordSet.MoveNext
End If
Loop
End With
Range("A1:D1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFilter
Range("C12").Select
End Sub
' Obtain local time zone bias from machine registry.
' This bias changes with Daylight Savings Time.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
Set objUser = GetObject("LDAP://" & strUserDN)
'--- These are the two relevant lines ---
Set objDate = objUser.pwdLastSet
dtmPwdLastSet = Integer8Date(objDate, lngBias)
Function Integer8Date(ByVal objDate, ByVal 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 ridiculously huge.
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