473,320 Members | 2,202 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,320 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 15006
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.