1

亲爱的 LotusScript 大师,

我正在开发一个 Lotus Notes 代理,它应该将我们的 Windows 2003 AD 与我们的 Lotus Domino 目录(V 7.0.3 服务器/客户端)同步。

我正在使用 ADODB.Connection 和 ADODB.Command 进程来连接它并查询 AD 用户。

这是命令文本:

objCommand.CommandText = "<LDAP://ou=DMHU Users,dc=some,dc=kindof,dc=domain>;(&(objectCategory=person)(objectClass=user));name,lastLogon;subTree"

然后我将访问“lastLogon”字段的内容:

objRecordSet.Fields("lastLogon").Value

但这是空的,而“名称”字段具有正确的值(我知道 lastLogon 字段是一个 64 位日期 - 整数左右)。

例如,在 VBScript 中使用相同的查询可以很好地接收 lastLogon 内容。

在 LotusScript 代码中使用类似 SQL 的查询也会给出相同的空 lastLogon 值。

有人有想法吗?

提前致谢!

4

1 回答 1

3

最后我找到了解决方案。

要访问 lastLogon (以及此类 AD 变量),首先必须设置一个接收当前 AD 用户对象的对象:

Set objUser = GetObject(rs.Fields("adspath").Value)

...

那么 lastLogon 也必须设置为一个对象:

Set objLastLogon = objUser.Get("lastLogonTimeStamp")

此 OLE 对象将有一个 HighPart 和一个 LowPart 成员。使用该成员可以计算上次登录日期和时间。

这篇博文让我大开眼界: http ://sgwindowsgroup.org/blogs/badz/archive/2010/03/01/querying-for-the-lastlogontimestamp-attribute-of-all-users-in-an-ou.aspx

这是我实现的功能,可以接收特定用户的CN和lastLogonTimeStamp。

Sub getADUserLastLogon(sUser As String)
    Dim workspace As New NotesUIWorkspace
    Dim conn As Variant
    Dim sRoot As String

    sRoot = "LDAP://ou=USERS_OR_WHATEVER,dc=my,dc=domain"

    Set oConn = CreateObject("ADODB.Connection")
    oConn.Provider = "ADSDSOObject"
    oConn.Open "Ads Provider", "USERNAME", "SECRETPWD" ' open connection with specific user credentials

    Dim rs
    Set rs = oConn.Execute("<" & sRoot & ">;(&(objectCategory=person)(objectClass=user)(cn=" & sUser & "));" &_
    "adspath,distinguishedname,sAMAccountName,cn,mail,telephoneNumber,lastLogonTimeStamp;subtree")

    While Not (rs.EOF)
        On Error Resume Next

        Set objUser = GetObject(rs.Fields("adspath").Value)

        'Print "getting user: " & objUser.Get("cn")

        Set objLastLogon = objUser.Get("lastLogonTimeStamp")

        Dim intLastLogonTime As Double

        intLastLogonTime = (objLastLogon.HighPart * (2^32)) + objLastLogon.LowPart ' due to the 64 bit number
        intLastLogonTime = intLastLogonTime / (60 * 10000000) ' convert from 100nanosec to minutes
        intLastLogonTime = intLastLogonTime + 60 ' local timezone
        intLastLogonTime = intLastLogonTime / 1440 ' convert to hours
        intLastLogonTime = intLastLogonTime + Datenumber(1601,1,1)

        Call workspace.CurrentDocument.Document.ReplaceItemValue("txtADResult", _
        workspace.CurrentDocument.FieldGetText("txtADResult") & Chr(13) & _
        rs.Fields("cn").Value & " Last Logon: " & Format$(Cdat(intLastLogonTime), "yyyy.mm.dd. hh:nn:ss"))

        rs.MoveNext
    Wend
End Sub
于 2012-11-20T13:11:48.163 回答