473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

lastLogonTimestamp

I am trying to write a VB app in VS.net to find the lastLogonTimestamp and
have found some example but the answer returned is always the same
'12/31/1600 7:00:00 PM' for any user account.

Thanks!

Below is a snippet of the code.

Dim Data1 As String
Dim Data3 As ActiveDs.LargeIntergerClass
Dim Data4 as Date
Din lngHigh, lngLow, timeAdj As Int64

Dim x As Integer = 0

' Bind to the Default Active Directory with the RootDSE object.
rootDSE = GetObject("LDAP://RootDSE")
sObjectDN = "LDAP://" & rootDSE.Get("defaultNamingContext")

Me.txtStatus.Text = "Connecting to: " & sObjectDN
Dim EntryPath As String = ("" & sObjectDN & "")
Entry = New DirectoryEntry(EntryPath)
Entry.RefreshCache()
Dim Searcher As New DirectorySearcher(Entry)
Searcher.PageSize = 5000
Dim strContact As String = "(&(objectClass=user)(mail=sue*))"
Searcher.Filter = strContact
Searcher.PropertiesToLoad.Add("cn")
Searcher.PropertiesToLoad.Add("lastLogon")
Searcher.PropertiesToLoad.Add("givenName")
Searcher.PropertiesToLoad.Add("sn")
Dim Results As System.DirectoryServices.SearchResult
On Error Resume Next
For Each Results In Searcher.FindAll()
Data1 = Nothing
Data3 = Nothing
If Not Results.GetDirectoryEntry().Properties("cn").Value =
Nothing Then
Data1 =
Results.GetDirectoryEntry().Properties("cn").Value .ToString
Else : GoTo Skip
End If
Data3 =
Results.GetDirectoryEntry().Properties("lastLogonT imestamp").Value
lngHigh = Data3.HighPart
lngLow = Data3.LowPart
timeAdj = lngHigh * (2 << 32) + lngLow
timeAdj = timeAdj / (60 * 10000000)
timeAdj = timeAdj / 1440
Data4 = DateTime.FromFileTime(timeAdj).ToShortDateString & " " &
DateTime.FromFileTime(timeAdj).ToShortTimeString
Data4 = Data4 + #1/1/1601#
Me.txtResults.Text = Me.txtResults.Text & Data1 & ", " & Data4 &
vbCrLf

Skip:

Next
Jul 17 '06 #1
7 18149
Kenneth H. Young schrieb:
I am trying to write a VB app in VS.net to find the lastLogonTimestamp and
have found some example but the answer returned is always the same
'12/31/1600 7:00:00 PM' for any user account.
THis means, that the value of lastLogonTimestamp is empty; probably
because the user never loged on.

Greetings

Dirk
Jul 18 '06 #2
In later testing that's what it seemed like a Null or Nothing returm.
But I am testing in a single Active Directory server environment against
known active accounts.
"Dirk_Drexlin_" <no***********@nospamhgs-calw.dewrote in message
news:4i************@individual.net...
Kenneth H. Young schrieb:
>I am trying to write a VB app in VS.net to find the lastLogonTimestamp
and
have found some example but the answer returned is always the same
'12/31/1600 7:00:00 PM' for any user account.

THis means, that the value of lastLogonTimestamp is empty; probably
because the user never loged on.

Greetings

Dirk

Jul 18 '06 #3
OK, I have tested over and over again. I have set the code up to pull
back all users and then tweaked it to pull from two different servers and
the results for every user is always the same for lastLogonTimeStamp
'12/31/1600 7:00:00 PM'. Any help with this will be greatly appreciated.
Below is all my code, please excuse the mess.

Imports System.DirectoryServices
Imports System.Windows.Forms
Imports ActiveDs
Imports ADODB

Public Class Form1
Dim Entry As DirectoryEntry
Dim Searcher As DirectorySearcher
Dim rootDSE As IADs
Dim sObjectDN As String
Dim timeAdj As Int64
Dim lngHigh As Int64
Dim lngLow As Int64

Private Sub btLastLogon_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btLastLogon.Click
Dim tDate As DateTime
Dim valLL As Date
tDate = Date.Now().AddDays(-30).ToShortDateString
Me.TextBox1.Text = tDate
Dim Data1, Data2 As String
Dim Data3 As ActiveDs.LargeInteger
Dim Data4, Data5 As Date
Dim x As Integer = 0
Dim llastLogonAdjust As Long = 127877417297554938L

' Bind to the Default Active Directory with the RootDSE object.
rootDSE = GetObject("LDAP://RootDSE")
sObjectDN = "LDAP://" & rootDSE.Get("defaultNamingContext")

Me.txtStatus.Text = "Connecting to: " & sObjectDN
Dim EntryPath As String = ("" & sObjectDN & "")
Entry = New DirectoryEntry(EntryPath)
Entry.UsePropertyCache = False
Dim Searcher As New DirectorySearcher(Entry)
Searcher.PageSize = 5000
Dim strContact As String = "(&(objectClass=user)(cn=*))"
Searcher.Filter = strContact
Searcher.PropertiesToLoad.Add("cn")
Searcher.PropertiesToLoad.Add("lastLogon")
Searcher.PropertiesToLoad.Add("givenName")
Searcher.PropertiesToLoad.Add("sn")
Searcher.PropertiesToLoad.Add("lastLogonTimestamp" )
Dim Results As System.DirectoryServices.SearchResult
On Error Resume Next
For Each Results In Searcher.FindAll()
If Not Results.GetDirectoryEntry().Properties("cn").Value =
Nothing Then
Data1 =
Results.GetDirectoryEntry().Properties("cn").Value .ToString
Else : GoTo Skip
End If
Data3 =
Results.GetDirectoryEntry().Properties("lastLogonT imestamp").Value
lngHigh = Data3.HighPart
lngLow = Data3.LowPart
timeAdj = lngHigh * (2 << 32) + lngLow
timeAdj = timeAdj / (60 * 10000000)
timeAdj = timeAdj / 1440
Data4 = DateTime.FromFileTime(timeAdj).ToShortDateString & " " &
DateTime.FromFileTime(timeAdj).ToShortTimeString
Data4 = Data4 + #1/1/1601#
Me.txtResults.Text = Me.txtResults.Text & Data1 & ", " & Data4 &
vbCrLf
x += 1
Skip:

Next
Entry.Close()
'Me.txtStatus.Text = "Found " & x & " entries."
End Sub
End Class
Jul 18 '06 #4
Are you sure, the problem is your program and not the Active Directory?

What value do you see when you check the properties of a user in the AD?

Greetings

Dirk
Jul 19 '06 #5
I have checked a large number of the users on the server using LDP as well
as Active Directory Users & Computers 'Additional Account Info' tab and they
are are populated with a date.

"Dirk_Drexlin_" <no***********@nospamhgs-calw.dewrote in message
news:4i************@individual.net...
Are you sure, the problem is your program and not the Active Directory?

What value do you see when you check the properties of a user in the AD?

Greetings

Dirk

Jul 19 '06 #6
Anytime I retrieve the lastlogon value from AD, I use the following
calculation, it works fine for me.

Dim UserDE as new
DirectoryEntry("LDAP://cn=sharpe\,travis,ou=users,dc=cahs,dc=colostate,dc =edu")

Dim highpart,lowpart,lastlogon as long
highpart = UserDE.Properties("LastLogonTimeStamp")(0).HighPar t
Lowpart = UserDE.Properties("LastLogonTimeStamp")(0).Lowpart
lastLogon = (HighPart * 2^32) - Lowpart

msgbox DateTime.FromFileTime(lastLogon)
Kenneth H. Young wrote:
I have checked a large number of the users on the server using LDP as well
as Active Directory Users & Computers 'Additional Account Info' tab and they
are are populated with a date.

"Dirk_Drexlin_" <no***********@nospamhgs-calw.dewrote in message
news:4i************@individual.net...
>Are you sure, the problem is your program and not the Active Directory?

What value do you see when you check the properties of a user in the AD?

Greetings

Dirk

Jul 20 '06 #7
THANK YOU!

That works and is the simplest solution I have seen to date.
"Travis Sharpe" <us**@anon.comwrote in message
news:eW**************@TK2MSFTNGP02.phx.gbl...
Anytime I retrieve the lastlogon value from AD, I use the following
calculation, it works fine for me.

Dim UserDE as new
DirectoryEntry("LDAP://cn=sharpe\,travis,ou=users,dc=cahs,dc=colostate,dc =edu")

Dim highpart,lowpart,lastlogon as long
highpart = UserDE.Properties("LastLogonTimeStamp")(0).HighPar t
Lowpart = UserDE.Properties("LastLogonTimeStamp")(0).Lowpart
lastLogon = (HighPart * 2^32) - Lowpart

msgbox DateTime.FromFileTime(lastLogon)
Kenneth H. Young wrote:
>I have checked a large number of the users on the server using LDP as
well as Active Directory Users & Computers 'Additional Account Info' tab
and they are are populated with a date.

"Dirk_Drexlin_" <no***********@nospamhgs-calw.dewrote in message
news:4i************@individual.net...
>>Are you sure, the problem is your program and not the Active Directory?

What value do you see when you check the properties of a user in the AD?

Greetings

Dirk
Jul 21 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
If anyone has an example of this I'd appreciate seeing it. I'm having a problem with assigning the value of an object's lastLogonTimeStamp property to a variable. I can do it with VbScript,...
0
by: Kenneth H. Young | last post by:
I am perplexed. I have a requirement to check for inactive accounts on a weekly basis so I am trying to write an application to aid in this. I get accurate results for very few user and the rest...
1
by: RC | last post by:
How easy would it be for me to send the result from this script to a txt or csv file. I also want to make sure it is getting the results from all Domain Controllers in the domain. The LLTS may vary...
0
by: drizzt76 | last post by:
My work's intranet actually works with Windows 2003 (PDC) and some NT (BDC), so the active directory works only in 2003 interim mode. I must list the "LastLogonTimeStamp" value of all the users of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.