首页 > 解决方案 > 使用 VBscript 从 AD 中的计算机对象获取 accountexpires

问题描述

我正在尝试从 Active Directory 中计算机对象的名为“accountExpires”的属性中获取日期。如果该对象尚未设置,它只会说“从不”,如果你看它只是有很多数字。我做了这个,它适用于属性“lastlogon”,但不适用于“accountExpires”。也许有人可以帮助我。

我正在使用 VBscript,因为我们公司在我们的登录脚本中使用了它。

On Error Resume Next

Dim ADSysInfo, objComputer, lobjDate, laccountExpiresDate, WSHShell
Set WSHShell = CreateObject("WScript.Shell")

Set ADSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & ADSysInfo.ComputerName)
msgbox objComputer
Set lobjDate = objComputer.get("lastLogon")         '   <----- Working ----->
'   Set lobjDate = objComputer.get("accountExpires")    ' <----- Not Working ----->
msgbox err.number
if IsNull(lobjDate) then
    msgbox "No Date"
else
    laccountExpiresDate = Integer8Date(lobjDate, getLocaltimeZoneBias)
    msgbox laccountExpiresDate
end if

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 bug 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
  Integer8Date = CDate(lngDate)
End Function  

' Obtain local time zone bias from machine registry.
Function getLocaltimeZoneBias  
  Dim lngBiasKey, lngBias

  lngBiasKey = WSHShell.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
  getLocaltimeZoneBias = lngBias
End Function 'getLocaltimeZoneBias   

标签: vbscript

解决方案


推荐阅读