Flexabust Bergson
Flexabust Bergson

Reputation: 762

How to convert a datetime to accountExpires AD Attribute?

I am using a DirectorySearcher filter that does not work, most probably because of a wrong form of accountExpires attribute from Active Directory. I would like to find all expired accounts using LDAP, but how can I convert DateTime.Now to accountExpires format? I have found lots on converting accountExpires to Datetime format but not the other way around. For example, I have found an example that says :

129383640000000000 is equivalent to Sat, 01 Jan 2011 14:00:00 GMT

How can I do it the other way? I know it is the interval of 100 nanoseconds from 1 JAn 1601 , but don't know how to calculate this

Upvotes: 0

Views: 2811

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174690

You need to convert it to FILETIME, as per the specification:

DateTime dt = DateTime.Now.AddDays(30);
long ftAccountExpires = dt.ToFileTime();

In the above example, if you set accountExpires to the value of ftAccountExpires, the account will expire 30 days from now

Upvotes: 1

Related Questions