J
Jerry Ham
Has anyone been able to get the "date" properties (pwdLastSet, lastLogon,
etc.) from Active Directory using JUST the native .Net tools (no com interop
with activeds)? When I try to do that, I get strange results. Consider the
following simple code:
(for this a .Net reference is set to System.DirectoryServices)
Private Function Test(ByVal sLDAPPath As String)
Dim de As New DirectoryEntry(sLDAPPath)
Dim sr As SearchResult
Dim ds As New DirectorySearcher(de)
Dim lTemp As Long
ds.PropertiesToLoad.Add("pwdLastSet")
ds.PropertiesToLoad.Add("lastLogon")
sr = ds.FindOne
If sr Is Nothing Then
'not found
Else
lTemp = sr.Properties.Item("pwdLastSet")(0)
End If
End Function
With MY user ID, lTemp ends up with 127133852422713849. That's fine, I can
use a DateTime.FromFileTime, but it comes back with a date that is about a
day off from what I get back using the interop (not just the UTC time
difference). I get similar results on other accounts (sometimes it is very
close, other times it is WAY off. When I use the Microsoft sample "Active
Directory Browser" (adsvw.exe) it shows this value should be
127133856717681145. Again, similar results on other accounts.
Samples:
above code adsvw.exe
127129877390570772 126626200214730160
126625284477162600 126625284477162600 (yes, this one comes out
the SAME!!!)
I know I can use something like this:
Private Sub Test(ByVal sLDAPPath As String)
Dim objUser As ActiveDs.IADsUser
objUser = GetObject(sLDAPPath)
Dim dt As Date = objUser.PasswordLastChanged()
End Sub
And it will work (as long as I referenced ActiveDS), but I do not really
want to ship the Interop.ActiveDS.dll along (or use COM) for this.
Anyone "been there, done that - solved it" that would share?
Thanks!
Jerry
etc.) from Active Directory using JUST the native .Net tools (no com interop
with activeds)? When I try to do that, I get strange results. Consider the
following simple code:
(for this a .Net reference is set to System.DirectoryServices)
Private Function Test(ByVal sLDAPPath As String)
Dim de As New DirectoryEntry(sLDAPPath)
Dim sr As SearchResult
Dim ds As New DirectorySearcher(de)
Dim lTemp As Long
ds.PropertiesToLoad.Add("pwdLastSet")
ds.PropertiesToLoad.Add("lastLogon")
sr = ds.FindOne
If sr Is Nothing Then
'not found
Else
lTemp = sr.Properties.Item("pwdLastSet")(0)
End If
End Function
With MY user ID, lTemp ends up with 127133852422713849. That's fine, I can
use a DateTime.FromFileTime, but it comes back with a date that is about a
day off from what I get back using the interop (not just the UTC time
difference). I get similar results on other accounts (sometimes it is very
close, other times it is WAY off. When I use the Microsoft sample "Active
Directory Browser" (adsvw.exe) it shows this value should be
127133856717681145. Again, similar results on other accounts.
Samples:
above code adsvw.exe
127129877390570772 126626200214730160
126625284477162600 126625284477162600 (yes, this one comes out
the SAME!!!)
I know I can use something like this:
Private Sub Test(ByVal sLDAPPath As String)
Dim objUser As ActiveDs.IADsUser
objUser = GetObject(sLDAPPath)
Dim dt As Date = objUser.PasswordLastChanged()
End Sub
And it will work (as long as I referenced ActiveDS), but I do not really
want to ship the Interop.ActiveDS.dll along (or use COM) for this.
Anyone "been there, done that - solved it" that would share?
Thanks!
Jerry