I have a vbs script converted to work via COM in autohotkey.
The function works with other attributes, like "cn", but it does not work with "lastLogon" - it returns blank.
I read here that the problem comes from the fact that vbs cannot correctly handle 64-bit values.
How can I do this, then?
Code: Select all
msgbox % GetUserAttribute("bobnewhart", "cn")
msgbox % GetUserAttribute("bobnewhart", "lastLogon") ;lastLogon is stored as Interger8 (8 bytes) - but VBS cannot handle 64-bit numbers directly and returns blank
Code: Select all
GetUserAttribute(whatusername, whatattribute){
objConnection := ComObjCreate("ADODB.Connection")
objCommand := ComObjCreate("ADODB.Command")
objRecordset := ComObjCreate("ADODB.Recordset")
strDomain := ComObjGet("LDAP://rootDSE").Get("defaultNamingContext")
objConnection.Open("Provider=ADsDSOObject;")
objCommand.ActiveConnection := objConnection
objCommand.CommandText := "<LDAP://" . strDomain . ">" . ";(&(objectCategory=person)(objectClass=user)(sAMAccountName=" . whatusername . "))" . ";" . whatattribute . ";subtree"
objRecordset := objCommand.Execute()
retval := objRecordset.Fields(whatattribute).value
alert(objRecordset.Fields(whatattribute) )
objRelease(objDomain)
objRelease(objConnection)
objRelease(objCommand)
return retval
}
VBS Code:
Code: Select all
' Example VBScript to display when an object last logged on
' Version 2.0 - August 2005
' ---------------------------------------------------------'
Option Explicit
Dim objOU, objUser, objRootDSE, objLastLogon
Dim strContainer, strDNSDomain
Dim intLastLogonTime, intGuyTime
' --------------------------------------------------------'
' Note: Please change OU=Droitwich, to reflect your domain
' --------------------------------------------------------'
strContainer = "OU=Droitwich, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
For Each objUser In objOU
Set objLastLogon = objUser.Get("lastLogon")
intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440
Wscript.Echo objUser.givenName & " 's last logon time: " _
& intLastLogonTime + #1/1/1601#
Next
WScript.Quit
' End of lastLogon example VBScript
objLastLogon := objUser.Get("lastLogon")