[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Microsoft Timestamp (Active Directory

Berger, Daniel

8/17/2006 6:03:00 PM

> -----Original Message-----
> From: Mikkel Bruun [mailto:devlists-ruby-talk@devlists.com]
> Sent: Thursday, August 17, 2006 11:43 AM
> To: ruby-talk ML
> Subject: Microsoft Timestamp (Active Directory)
>
>
> Active Directory users contain an attribute called
> lastlogontimestamp...
>
> its in this format:
> 128002727440808261
>
> How do I convert this to something more....nice???

Leave it to Microsoft to come up with something this convoluted:

http://www.microsoft.com/technet/scriptcenter/topics/win2003/l...
spx

This seems to work:

require 'date'

last_logon = 128002727440808261

base = Date.new(1601, 1, 1)
base += last_logon / (60 * 10000000 * 1440)

p base.to_s # "2006-08-17"

Regards,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

9 Answers

Stefan Lang

8/17/2006 6:49:00 PM

0

Amazing...

Thanks a bunch

Mikkel
On Friday, August 18, 2006, at 3:03 AM, Berger, Daniel wrote:
>> -----Original Message-----
>> From: Mikkel Bruun [mailto:devlists-ruby-talk@devlists.com]
>> Sent: Thursday, August 17, 2006 11:43 AM
>> To: ruby-talk ML
>> Subject: Microsoft Timestamp (Active Directory)
>>
>>
>> Active Directory users contain an attribute called
>> lastlogontimestamp...
>>
>> its in this format:
>> 128002727440808261
>>
>> How do I convert this to something more....nice???
>
>Leave it to Microsoft to come up with something this convoluted:
>
>http://www.microsoft.com/technet/scriptcenter/topics/win2003/l...
>spx
>
>This seems to work:
>
>require 'date'
>
>last_logon = 128002727440808261
>
>base = Date.new(1601, 1, 1)
>base += last_logon / (60 * 10000000 * 1440)
>
>p base.to_s # "2006-08-17"
>
>Regards,
>
>Dan
>
>
>This communication is the property of Qwest and may contain confidential or
>privileged information. Unauthorized use of this communication is strictly
>prohibited and may be unlawful. If you have received this communication
>in error, please immediately notify the sender by reply e-mail and destroy
>all copies of the communication and any attachments.
>


Mikkel Bruun

www.strongside.dk - Football Portal(DK)
ting.minline.dk - Buy Old Stuff!(DK)



--
Posted with http://De.... Sign up and save your mailbox.

Clifford Heath

8/18/2006 1:44:00 PM

0

Berger, Daniel wrote:
> Leave it to Microsoft to come up with something this convoluted:

What could possibly be *less* convoluted than keeping time as a
high resolution (in this case, 100ns) integer since some epoch?
It's actually the *perfect* way to handle time, and I thought
that (and implemented it) long before I knew MS had done it.

Francis Cianfrocca

8/18/2006 2:51:00 PM

0

On 8/18/06, Clifford Heath <no@spam.please.net> wrote:
> Berger, Daniel wrote:
> > Leave it to Microsoft to come up with something this convoluted:
>
> What could possibly be *less* convoluted than keeping time as a
> high resolution (in this case, 100ns) integer since some epoch?
> It's actually the *perfect* way to handle time, and I thought
> that (and implemented it) long before I knew MS had done it.
>
>

Check the NTP protocol. This sounds like the format used by NTP servers.

Hal E. Fulton

8/18/2006 10:39:00 PM

0

Daniel Martin wrote:
> "Berger, Daniel" <Daniel.Berger@qwest.com> writes:
>
>
>>Leave it to Microsoft to come up with something this convoluted:
>
>
> At least their time 0 is close to the beginning of a century

Actually it's *at* the beginning of a century.


Hal

Jeff Schwab

8/18/2006 10:50:00 PM

0

Hal Fulton wrote:
> Daniel Martin wrote:
>> "Berger, Daniel" <Daniel.Berger@qwest.com> writes:
>>
>>
>>> Leave it to Microsoft to come up with something this convoluted:
>>
>>
>> At least their time 0 is close to the beginning of a century
>
> Actually it's *at* the beginning of a century.

It's *at* the end of the century, since the Gregorian calendar began
with year 1, not year 0.

Jeff Schwab

8/18/2006 11:05:00 PM

0

Jeffrey Schwab wrote:
> Hal Fulton wrote:
>> Daniel Martin wrote:
>>> "Berger, Daniel" <Daniel.Berger@qwest.com> writes:
>>>
>>>
>>>> Leave it to Microsoft to come up with something this convoluted:
>>>
>>>
>>> At least their time 0 is close to the beginning of a century
>>
>> Actually it's *at* the beginning of a century.
>
> It's *at* the end of the century, since the Gregorian calendar began
> with year 1, not year 0.

Whoops. Please ignore me.

Charles Leeds

1/11/2007 10:12:00 PM

0


How did you get the lastlogontimestamp attribute into integer format?

Retrieving myuser.lastLogonTimestamp always gives me:

#<WIN32OLE:0x6e39ee0>

Which I have no idea how to deal with.

Thanks,

Charles Leeds

Mikkel Bruun wrote:
> Amazing...
>
> Thanks a bunch
>
> Mikkel
> On Friday, August 18, 2006, at 3:03 AM, Berger, Daniel wrote:
>
>>> -----Original Message-----
>>> From: Mikkel Bruun [mailto:devlists-ruby-talk@devlists.com]
>>> Sent: Thursday, August 17, 2006 11:43 AM
>>> To: ruby-talk ML
>>> Subject: Microsoft Timestamp (Active Directory)
>>>
>>>
>>> Active Directory users contain an attribute called
>>> lastlogontimestamp...
>>>
>>> its in this format:
>>> 128002727440808261
>>>
>>> How do I convert this to something more....nice???
>>>
>> Leave it to Microsoft to come up with something this convoluted:
>>
>> http://www.microsoft.com/technet/scriptcenter/topics/win2003/l...
>> spx
>>
>> This seems to work:
>>
>> require 'date'
>>
>> last_logon = 128002727440808261
>>
>> base = Date.new(1601, 1, 1)
>> base += last_logon / (60 * 10000000 * 1440)
>>
>> p base.to_s # "2006-08-17"
>>
>> Regards,
>>
>> Dan
>>
>>
>> This communication is the property of Qwest and may contain confidential or
>> privileged information. Unauthorized use of this communication is strictly
>> prohibited and may be unlawful. If you have received this communication
>> in error, please immediately notify the sender by reply e-mail and destroy
>> all copies of the communication and any attachments.
>>
>>
>
>
> Mikkel Bruun
>
> www.strongside.dk - Football Portal(DK)
> ting.minline.dk - Buy Old Stuff!(DK)
>
>
>
>


Charles Leeds

1/12/2007 1:55:00 PM

0

For just documentation purposes - here is some dirty sample code on how
to get a Ruby DateTime from Active Directory:

require 'win32ole'
require 'date'

# AD4Ruby
require './ad4r/config.rb'

# Import namespace for AD4R
include ActiveDirectory

myuser = User.find_by_logon('cll13291')

highpart = myuser.ldap_object.__send__("Get", "lastLogon" ).HighPart
lowpart = myuser.ldap_object.__send__("Get", "lastLogon" ).LowPart

puts "HighPart: " + highpart.to_s
puts "LowPart: " + lowpart.to_s
intLogonTime = highpart * (2**32) + lowpart
puts intLogonTime
intLogonFloat = intLogonTime.to_f / (60 * 10000000 * 1440).to_f
puts "%.9f" % intLogonFloat

last_logon = intLogonFloat

base = DateTime.new(1601,1,1,0,0,0)
base += intLogonFloat

p base
p base.to_s # "2006-08-17T12:37:10Z"



Charles Leeds wrote:
>
> How did you get the lastlogontimestamp attribute into integer format?
>
> Retrieving myuser.lastLogonTimestamp always gives me:
>
> #<WIN32OLE:0x6e39ee0>
>
> Which I have no idea how to deal with.
>
> Thanks,
>
> Charles Leeds
>
> Mikkel Bruun wrote:
>> Amazing...
>>
>> Thanks a bunch
>>
>> Mikkel
>> On Friday, August 18, 2006, at 3:03 AM, Berger, Daniel wrote:
>>
>>>> -----Original Message-----
>>>> From: Mikkel Bruun [mailto:devlists-ruby-talk@devlists.com]
>>>> Sent: Thursday, August 17, 2006 11:43 AM
>>>> To: ruby-talk ML
>>>> Subject: Microsoft Timestamp (Active Directory)
>>>>
>>>>
>>>> Active Directory users contain an attribute called
>>>> lastlogontimestamp...
>>>>
>>>> its in this format:
>>>> 128002727440808261
>>>>
>>>> How do I convert this to something more....nice???
>>>>
>>> Leave it to Microsoft to come up with something this convoluted:
>>>
>>> http://www.microsoft.com/technet/scriptcenter/topics/win2003/l...
>>>
>>> spx
>>>
>>> This seems to work:
>>>
>>> require 'date'
>>>
>>> last_logon = 128002727440808261
>>>
>>> base = Date.new(1601, 1, 1)
>>> base += last_logon / (60 * 10000000 * 1440)
>>>
>>> p base.to_s # "2006-08-17"
>>>
>>> Regards,
>>>
>>> Dan
>>>
>>>
>>> This communication is the property of Qwest and may contain
>>> confidential or
>>> privileged information. Unauthorized use of this communication is
>>> strictly
>>> prohibited and may be unlawful. If you have received this
>>> communication
>>> in error, please immediately notify the sender by reply e-mail and
>>> destroy
>>> all copies of the communication and any attachments.
>>>
>>>
>>
>>
>> Mikkel Bruun
>>
>> www.strongside.dk - Football Portal(DK)
>> ting.minline.dk - Buy Old Stuff!(DK)
>>
>>
>>
>>
>
>
>
>
>


Benjamin Ritcey

1/14/2007 3:49:00 AM

0

I found the following code a bit clearer, but YMMV; this was running
under Linux & just grabbing lastLogin via LDAP.

HTH,

-b

# constants for converting to/from AD's wacky time format
#http://www.irishdev.com/blogs/jbrennan/archive/2005/09/0...
# was helpful in figuring this out

AD_EPOCH = 116_444_736_000_000_000
AD_MULTIPLIER = 10_000_000

# convert a Time object to AD's epoch
def time2ad(time)
(time.to_i * AD_MULTIPLIER) + AD_EPOCH
end

# convert from AD's time string to a Time object
def ad2time(time)
Time.at((time.to_i - AD_EPOCH) / AD_MULTIPLIER)
end



On Fri, 2007-01-12 at 22:54 +0900, Charles Leeds wrote:
> For just documentation purposes - here is some dirty sample code on how
> to get a Ruby DateTime from Active Directory:
>
> require 'win32ole'
> require 'date'
>
> # AD4Ruby
> require './ad4r/config.rb'
>
> # Import namespace for AD4R
> include ActiveDirectory
>
> myuser = User.find_by_logon('cll13291')
>
> highpart = myuser.ldap_object.__send__("Get", "lastLogon" ).HighPart
> lowpart = myuser.ldap_object.__send__("Get", "lastLogon" ).LowPart
>
> puts "HighPart: " + highpart.to_s
> puts "LowPart: " + lowpart.to_s
> intLogonTime = highpart * (2**32) + lowpart
> puts intLogonTime
> intLogonFloat = intLogonTime.to_f / (60 * 10000000 * 1440).to_f
> puts "%.9f" % intLogonFloat
>
> last_logon = intLogonFloat
>
> base = DateTime.new(1601,1,1,0,0,0)
> base += intLogonFloat
>
> p base
> p base.to_s # "2006-08-17T12:37:10Z"
>
>
>
> Charles Leeds wrote:
> >
> > How did you get the lastlogontimestamp attribute into integer format?
> >
> > Retrieving myuser.lastLogonTimestamp always gives me:
> >
> > #<WIN32OLE:0x6e39ee0>
> >
> > Which I have no idea how to deal with.
> >
> > Thanks,
> >
> > Charles Leeds
> >
> > Mikkel Bruun wrote:
> >> Amazing...
> >>
> >> Thanks a bunch
> >>
> >> Mikkel
> >> On Friday, August 18, 2006, at 3:03 AM, Berger, Daniel wrote:
> >>
> >>>> -----Original Message-----
> >>>> From: Mikkel Bruun [mailto:devlists-ruby-talk@devlists.com]
> >>>> Sent: Thursday, August 17, 2006 11:43 AM
> >>>> To: ruby-talk ML
> >>>> Subject: Microsoft Timestamp (Active Directory)
> >>>>
> >>>>
> >>>> Active Directory users contain an attribute called
> >>>> lastlogontimestamp...
> >>>>
> >>>> its in this format:
> >>>> 128002727440808261
> >>>>
> >>>> How do I convert this to something more....nice???
> >>>>
> >>> Leave it to Microsoft to come up with something this convoluted:
> >>>
> >>> http://www.microsoft.com/technet/scriptcenter/topics/win2003/l...
> >>>
> >>> spx
> >>>
> >>> This seems to work:
> >>>
> >>> require 'date'
> >>>
> >>> last_logon = 128002727440808261
> >>>
> >>> base = Date.new(1601, 1, 1)
> >>> base += last_logon / (60 * 10000000 * 1440)
> >>>
> >>> p base.to_s # "2006-08-17"
> >>>
> >>> Regards,
> >>>
> >>> Dan
> >>>
> >>>
> >>> This communication is the property of Qwest and may contain
> >>> confidential or
> >>> privileged information. Unauthorized use of this communication is
> >>> strictly
> >>> prohibited and may be unlawful. If you have received this
> >>> communication
> >>> in error, please immediately notify the sender by reply e-mail and
> >>> destroy
> >>> all copies of the communication and any attachments.
> >>>
> >>>
> >>
> >>
> >> Mikkel Bruun
> >>
> >> www.strongside.dk - Football Portal(DK)
> >> ting.minline.dk - Buy Old Stuff!(DK)
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
>
>
>