$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
About Virtualization, VDI, SBC, Application Compatibility and anything else I feel like
10 Feb // php the_time('Y') ?>
I am writing a class that wraps Active Directory into Objects that live in an Objectlist, much like my Terminal Server class in the Jedi Windows Security Library.
One of the classes is TJwADUser that represents an Active Directory user with all kinds of properties. So while I was implementing them I stumbled upon the accountExpires attribute which is implemented as an 8 byte integer so I figured I could read it as Int64, cast this to TFileTime (FILETIME) and convert to TDateTime.
This raised an error however (EVariantTypeCastError with message ‘Could not convert variant of type (Dispatch) into type (Double)’.).
So I checked what kind of variant Active Directory returns and it is not the expected varInt64 but varDispatch.
It turns out that we need the IADsLargeInteger interface to obtain the correct values. The code below works for me:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function TJwADUser.GetExpirationDate: TDateTime; var LargeInteger: IADsLargeInteger; ft: TFileTime; v: Variant; begin if Get('accountExpires', v) then begin LargeInteger := IDispatch(v) as IADsLargeInteger; ft.dwLowDateTime := LargeInteger.LowPart; ft.dwHighDateTime := LargeInteger.HighPart; if Int64(ft) = 0 then Result := 0 else Result := FileTime2DateTime(ft) end else begin Result := 0; end; end; |
Notes: The Get function is a wrapper for IADs(User).Get(Ex) so you can ignore that and my function returns 0 when the value is empty or on read failure.
2 Responses for "Reading accountExpires attribute from Active Directory (in Delphi)"
I must inform readers that the line
if Int64(ft) = 0 then
creates an alignment fault which isn’t problematic in x86 but is still wrong. Raymond Chen reported about this very same issue some time ago
http://blogs.msdn.com/oldnewthing/archive/2004/08/25/220195.aspx
Correction:
I meant “could create an alignment fault..”
Of course the fault isn’t thrown at all because SW and HW corrects it.
Leave a reply