b***@gmail.com
2005-11-04 22:09:38 UTC
I am fetching the LastLogonTimeStamp value (Long) from AD using vb.net
DirectorySearcher code. What I can't understand is how to convert the
Long value to a datetime value, without resorting to w32tm, or
something external. I can see plenty of ways to do it in vbscript, but
what about vb.net? Preferably without the compatibility dll...
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://"
& aDomains(i))
Dim output, strFilter As String, intlastlogontime As Long
output = ""
strFilter =
"(&(objectclass=computer)(operatingSystem=Windows XP Professional))"
Dim oSearcher As New
System.DirectoryServices.DirectorySearcher(entry, strFilter)
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
oSearcher.SearchScope = SearchScope.Subtree
oSearcher.ReferralChasing = ReferralChasingOption.All
oSearcher.PageSize = 1000
oSearcher.PropertiesToLoad.AddRange(New String() {"name",
"createTimeStamp", "lastlogontimestamp"})
oResults = oSearcher.FindAll
If oResults.Count <> Nothing Then
If oResults.Count <> 0 Then
'iterate the collection
Dim name, ct As String, llt As Long, llt2 As
DateTime
For Each oResult In oResults
Try
name = CStr(oResult.Properties("name")(0))
Catch ex As Exception
name = ""
End Try
Try
ct =
CStr(oResult.Properties("createtimestamp")(0))
Catch ex As Exception
ct = ""
End Try
Try
llt =
CLng(oResult.Properties("lastlogontimestamp")(0))
Catch ex As Exception
End Try
'*******HERE'S HOW THEY SAY TO DO IT IN VBSCRIPT (WON'T WORK IN
.NET)*****
'intlastlogontime = llt.Highpart * (2 ^ 32) +
llt.LowPart
'intLastLogonTime = intLastLogonTime / (60 *
10000000)
'intLastLogonTime = intLastLogonTime / 1440
'***************************************************************************************************
fw.WriteLine(name & ControlChars.Tab & ct &
ControlChars.Tab & llt.ToString)
Next
End If
End If
DirectorySearcher code. What I can't understand is how to convert the
Long value to a datetime value, without resorting to w32tm, or
something external. I can see plenty of ways to do it in vbscript, but
what about vb.net? Preferably without the compatibility dll...
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://"
& aDomains(i))
Dim output, strFilter As String, intlastlogontime As Long
output = ""
strFilter =
"(&(objectclass=computer)(operatingSystem=Windows XP Professional))"
Dim oSearcher As New
System.DirectoryServices.DirectorySearcher(entry, strFilter)
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
oSearcher.SearchScope = SearchScope.Subtree
oSearcher.ReferralChasing = ReferralChasingOption.All
oSearcher.PageSize = 1000
oSearcher.PropertiesToLoad.AddRange(New String() {"name",
"createTimeStamp", "lastlogontimestamp"})
oResults = oSearcher.FindAll
If oResults.Count <> Nothing Then
If oResults.Count <> 0 Then
'iterate the collection
Dim name, ct As String, llt As Long, llt2 As
DateTime
For Each oResult In oResults
Try
name = CStr(oResult.Properties("name")(0))
Catch ex As Exception
name = ""
End Try
Try
ct =
CStr(oResult.Properties("createtimestamp")(0))
Catch ex As Exception
ct = ""
End Try
Try
llt =
CLng(oResult.Properties("lastlogontimestamp")(0))
Catch ex As Exception
End Try
'*******HERE'S HOW THEY SAY TO DO IT IN VBSCRIPT (WON'T WORK IN
.NET)*****
'intlastlogontime = llt.Highpart * (2 ^ 32) +
llt.LowPart
'intLastLogonTime = intLastLogonTime / (60 *
10000000)
'intLastLogonTime = intLastLogonTime / 1440
'***************************************************************************************************
fw.WriteLine(name & ControlChars.Tab & ct &
ControlChars.Tab & llt.ToString)
Next
End If
End If