vbscript - 使用 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
解决方案
推荐阅读
- c++ - C ++中的用户定义数组和冒泡排序
- android - Android 单元测试 ViewModel 与 Mockk
- typescript - instanceof Array 和 Array.isArray 不会将泛型类型缩小到 Array
- visual-studio-code - 向 Jupyter 笔记本添加标签
- java - Log4j2 翻转问题
- java - 需要帮助在 Java 中移动拉丁方
- flutter - 向小部件构建添加参数
- django - 使用id上传新文件时如何删除以前上传的文件
- java - android警报管理器的问题,当应用程序关闭时
- sql - 用于查找列数的 SQL 查询