AccountExpires Property in AD

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

Hello,

I am working on some code that creates a new user object in AD and in
certain circumstances the AccountExpires property must be set. This value
exists as a Long (int64) value and so my question is this: How do I convert a
date value to an acceptable Long datatype using VB.Net code?
 
Hi Ryan,

Just performed some search and the long integer date value of
AccountExpires in AD seems convertable through the "FileTime" format of
DateTime class in .net. Here is a former thread which has discussed on this
and some additional validation will require. the code there read long int
value into DateTime, you may try the reverse way (DateTime class has both
ToFileTime and FromFileTime methods):

#Converting AD Expire Date to DateTime
http://www.thescripts.com/forum/thread255732.html

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------VHdGrIQ==
 
Hi Steven,

Thanks for your reply. I did track down my answer shortly before getting
your response. You are correct that you need the System.DateTime.toFileTime
method to first convert the datatime to a long (int64). Then you need a
reference to activeds.tlb (COM tab in Add Reference) to access the class
ActiveDs.IADsLargeInteger and the code below converts the long integer into
IADsLargeInteger that ADSI will accept for these types of date fields:

Function GetLargeInteger(ByVal val As Int64) As IADsLargeInteger
Dim largeInt As New ActiveDs.LargeIntegerClass

largeInt.HighPart = CType((val >> 32), Integer)
val = val << 32
val = val >> 32
largeInt.LowPart = (Convert.ToInt32(val))
return largeInt
End Function

Ref: http://directoryprogramming.net/forums/thread/2539.aspx

--
Ryan


Steven Cheng said:
Hi Ryan,

Just performed some search and the long integer date value of
AccountExpires in AD seems convertable through the "FileTime" format of
DateTime class in .net. Here is a former thread which has discussed on this
and some additional validation will require. the code there read long int
value into DateTime, you may try the reverse way (DateTime class has both
ToFileTime and FromFileTime methods):

#Converting AD Expire Date to DateTime
http://www.thescripts.com/forum/thread255732.html

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------VHdGrIQ==
 
Thanks for your reply Ryan,

I'm glad that you've got a complete solution on this.

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?Unlhbg==?= <[email protected]>
Subject: RE: AccountExpires Property in AD
Date: Tue, 12 Feb 2008 05:20:03 -0800
Hi Steven,

Thanks for your reply. I did track down my answer shortly before getting
your response. You are correct that you need the System.DateTime.toFileTime
method to first convert the datatime to a long (int64). Then you need a
reference to activeds.tlb (COM tab in Add Reference) to access the class
ActiveDs.IADsLargeInteger and the code below converts the long integer into
IADsLargeInteger that ADSI will accept for these types of date fields:

Function GetLargeInteger(ByVal val As Int64) As IADsLargeInteger
Dim largeInt As New ActiveDs.LargeIntegerClass

largeInt.HighPart = CType((val >> 32), Integer)
val = val << 32
val = val >> 32
largeInt.LowPart = (Convert.ToInt32(val))
return largeInt
End Function

Ref: http://directoryprogramming.net/forums/thread/2539.aspx
 
Back
Top