473,396 Members | 1,997 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,396 software developers and data experts.

How do I get "lastLogon" from ActiveDirectory

Hi all,

I am trying to get the field "lastLogon" out of ActiveDirectory.
It should be trivial I thought, but it is not, as I have experienced.

private DataRow FillDataRow( DataRow dataRow, PropertyValueCollection
property , string columnName )
{

if( columnName.Equals("Last Login") && property.Value != null )
{
dataRow[columnName] = property[0];
}

}

I dont have any problems to get all string data from
PropertyValueCollection.

But how do I convert property[0] to DateTime. ( Type of the Object is
System.__ComObject ) thats at least what I know about.

I dont find any example on the net.

thx
a.s.

Nov 15 '05 #1
4 15022
The LastLogon property in ActiveDirectory is a large integer. You need to
reference the ActiveDS.dll COM library and use the LargeInteger interface to
get the high and low parts of the 64 bit integer that it is. The value is a
FileTime value which you can then convert to a .NET DateTime object.

Btw: Note that this is no non-replicated property so that the value you get
is the lastLogon handled by that specific domain controller. To get the
actual Lastlogon you would need to query the value from all
domaincontrollers in the domain and use the highest value.

Arild

"Sargas Atum" <at**@gmx.net> wrote in message
news:40********@news.piro.net...
Hi all,

I am trying to get the field "lastLogon" out of ActiveDirectory.
It should be trivial I thought, but it is not, as I have experienced.

private DataRow FillDataRow( DataRow dataRow, PropertyValueCollection
property , string columnName )
{

if( columnName.Equals("Last Login") && property.Value != null )
{
dataRow[columnName] = property[0];
}

}

I dont have any problems to get all string data from
PropertyValueCollection.

But how do I convert property[0] to DateTime. ( Type of the Object is
System.__ComObject ) thats at least what I know about.

I dont find any example on the net.

thx
a.s.

Nov 15 '05 #2
Arild Bakken wrote:
The LastLogon property in ActiveDirectory is a large integer. You need to
reference the ActiveDS.dll COM library and use the LargeInteger interface to
get the high and low parts of the 64 bit integer that it is. The value is a
FileTime value which you can then convert to a .NET DateTime object.

Btw: Note that this is no non-replicated property so that the value you get
is the lastLogon handled by that specific domain controller. To get the
actual Lastlogon you would need to query the value from all
domaincontrollers in the domain and use the highest value.

Arild

"Sargas Atum" <at**@gmx.net> wrote in message
news:40********@news.piro.net...
Hi all,

I am trying to get the field "lastLogon" out of ActiveDirectory.
It should be trivial I thought, but it is not, as I have experienced.

private DataRow FillDataRow( DataRow dataRow, PropertyValueCollection
property , string columnName )
{

if( columnName.Equals("Last Login") && property.Value != null )
{
dataRow[columnName] = property[0];
}

}

I dont have any problems to get all string data from
PropertyValueCollection.

But how do I convert property[0] to DateTime. ( Type of the Object is
System.__ComObject ) thats at least what I know about.

I dont find any example on the net.

thx
a.s.



Do you have any example how to do it in c#? I found only some examples
in VB, though modified they dont work.

thx
a.s.

Nov 15 '05 #3
LargeInteger largeInt = (LargeInteger)objUser.Properties["lastLogon"][0];
Int64 liTicks = largeInt.HighPart * 0x100000000 + largeInt.LowPart;
if(DateTime.MaxValue.Ticks >= liTicks && DateTime.MinValue.Ticks <= liTicks)
{
DateTime dTemp = DateTime.FromFileTime(liTicks);
}

"Sargas Atum" <at**@gmx.net> wrote in message
news:40********@news.piro.net...
Arild Bakken wrote:
The LastLogon property in ActiveDirectory is a large integer. You need to reference the ActiveDS.dll COM library and use the LargeInteger interface to get the high and low parts of the 64 bit integer that it is. The value is a FileTime value which you can then convert to a .NET DateTime object.

Btw: Note that this is no non-replicated property so that the value you get is the lastLogon handled by that specific domain controller. To get the
actual Lastlogon you would need to query the value from all
domaincontrollers in the domain and use the highest value.

Arild

"Sargas Atum" <at**@gmx.net> wrote in message
news:40********@news.piro.net...
Hi all,

I am trying to get the field "lastLogon" out of ActiveDirectory.
It should be trivial I thought, but it is not, as I have experienced.

private DataRow FillDataRow( DataRow dataRow, PropertyValueCollection
property , string columnName )
{

if( columnName.Equals("Last Login") && property.Value != null )
{
dataRow[columnName] = property[0];
}

}

I dont have any problems to get all string data from
PropertyValueCollection.

But how do I convert property[0] to DateTime. ( Type of the Object is
System.__ComObject ) thats at least what I know about.

I dont find any example on the net.

thx
a.s.



Do you have any example how to do it in c#? I found only some examples
in VB, though modified they dont work.

thx
a.s.

Nov 15 '05 #4
Arild Bakken wrote:
LargeInteger largeInt = (LargeInteger)objUser.Properties["lastLogon"][0];
Int64 liTicks = largeInt.HighPart * 0x100000000 + largeInt.LowPart;
if(DateTime.MaxValue.Ticks >= liTicks && DateTime.MinValue.Ticks <= liTicks)
{
DateTime dTemp = DateTime.FromFileTime(liTicks);
}

This works exactly as you wrote it down :)

Thx
Have a nice day.
a.s.

Nov 15 '05 #5

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

Similar topics

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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.