How do I get "lastLogon" from ActiveDirectory |
P: n/a
|
Sargas Atum
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. | |
Share this Question
|
P: n/a
|
Arild Bakken
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" <atum@gmx.net> wrote in message
news:4007efc2$1@news.piro.net...[color=blue]
> 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.
>[/color] | | |
P: n/a
|
Sargas Atum
Arild Bakken wrote:
[color=blue]
> 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" <atum@gmx.net> wrote in message
> news:4007efc2$1@news.piro.net...
>[color=green]
>>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.
>>[/color]
>
>
>[/color]
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. | | |
P: n/a
|
Arild Bakken
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" <atum@gmx.net> wrote in message
news:4007ff3a$1@news.piro.net...[color=blue]
> Arild Bakken wrote:
>[color=green]
> > The LastLogon property in ActiveDirectory is a large integer. You need[/color][/color]
to[color=blue][color=green]
> > reference the ActiveDS.dll COM library and use the LargeInteger[/color][/color]
interface to[color=blue][color=green]
> > get the high and low parts of the 64 bit integer that it is. The value[/color][/color]
is a[color=blue][color=green]
> > 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[/color][/color]
get[color=blue][color=green]
> > 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" <atum@gmx.net> wrote in message
> > news:4007efc2$1@news.piro.net...
> >[color=darkred]
> >>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.
> >>[/color]
> >
> >
> >[/color]
>
> 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.
>[/color] | | |
P: n/a
|
Sargas Atum
Arild Bakken wrote:
[color=blue]
> 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);
> }
>[/color]
This works exactly as you wrote it down :)
Thx
Have a nice day.
a.s. | | Post your reply Help answer this question
Didn't find the answer to your C# / C Sharp question?
| | Question stats - viewed: 6950
- replies: 4
- date asked: Nov 15 '05
| |