By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,029 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,029 IT Pros & Developers. It's quick & easy.

getting the PwdLastSet attrib value though .net

P: n/a
Hello there
I need to get the "PwdLastSet" of a user object to know when he last set his
password.
I am using DirectoryServices.DirectoryEntry to bind to the user object, but
it either gives "Argument 'Prompt' cannot be converted to type 'String'." or
when I use .tostring it returns "system._comobject"
I even tried to use this line but it also failed
dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast from
type '_ComObject' to type 'Long' is not valid.
I use the code below:
Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://cn=sameh
ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject" '
"Argument 'Prompt' cannot be converted to type 'String'."
Any ideas?
Thanks in advance
Sameh
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I think the pwdlastset attribute is a concatenated version of two distinct
dates. I did a quick search for pwdlastset and came across this vbscript
block. You can get some ideas from this.

http://www.rlmueller.net/Programs/PwdLastSet.txt
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
Hello there
I need to get the "PwdLastSet" of a user object to know when he last set
his
password.
I am using DirectoryServices.DirectoryEntry to bind to the user object,
but
it either gives "Argument 'Prompt' cannot be converted to type 'String'."
or
when I use .tostring it returns "system._comobject"
I even tried to use this line but it also failed
dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast from
type '_ComObject' to type 'Long' is not valid.
I use the code below:
Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://cn=sameh
ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject"
'
"Argument 'Prompt' cannot be converted to type 'String'."
Any ideas?
Thanks in advance
Sameh

Nov 21 '05 #2

P: n/a
There are basically two ways to get the Int64 value you need.

If you use the DirectorySearcher, it marshals AD INTEGER8 types to .NET
Int64 automatically, so no work needs to be done. This is by far the
easiest way.

If you use the DirectoryEntry, it marshals the value as an ADSI
IADsLargeInteger type, which at runtime is a System.__ComObject. This is
annoying, but you can get the value with a little interop and some data
munging. This works for me:

dim entry as new DirectoryEntry("LDAP://yourdn here")
dim pwd as object = entry.Properties("pwdLastSet").Value
dim pwdDate as DateTime
pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger( pwd))

Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64

dim low as int32
dim high as int32
dim valBytes(7) as byte

dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger)
low = longInt.LowPart
high = longInt.HighPart

BitConverter.GetBytes(low).CopyTo(valBytes, 0)
BitConverter.GetBytes(high).CopyTo(valBytes, 4)

Return BitConverter.ToInt64(valBytes, 0)

End Function
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface

Note that you can also get the high and low values via reflection and late
binding or by importing the activeds.dll COM object into .NET.

Note that the DateTime you get back will be in Utc, so if you need local
time, make sure you call ToLocalTime.

HTH,

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
Hello there
I need to get the "PwdLastSet" of a user object to know when he last set
his
password.
I am using DirectoryServices.DirectoryEntry to bind to the user object,
but
it either gives "Argument 'Prompt' cannot be converted to type 'String'."
or
when I use .tostring it returns "system._comobject"
I even tried to use this line but it also failed
dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast from
type '_ComObject' to type 'Long' is not valid.
I use the code below:
Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://cn=sameh
ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject"
'
"Argument 'Prompt' cannot be converted to type 'String'."
Any ideas?
Thanks in advance
Sameh

Nov 21 '05 #3

P: n/a
Dear Joe
Thanks for replying
as i am totaly new to the develeopment field i tried to understand the code
that you sent.
But after a long time i decided to copy it to my form and see what happens
this part (that i failed to understand)
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface IADsLargeInteger
Property HighPart() As Int32
Property LowPart() As Int32
End Interface

fails with the following errors:

Attribute cannot be used on 'IADsLargeInteger'.
Type 'ComImport' is not defined.
Type 'InterfaceTypeAttribute' is not defined.

i would rerall appriciate it if you tell me what i should do .
thanks again

"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:e0**************@tk2msftngp13.phx.gbl...
There are basically two ways to get the Int64 value you need.

If you use the DirectorySearcher, it marshals AD INTEGER8 types to .NET
Int64 automatically, so no work needs to be done. This is by far the
easiest way.

If you use the DirectoryEntry, it marshals the value as an ADSI
IADsLargeInteger type, which at runtime is a System.__ComObject. This is
annoying, but you can get the value with a little interop and some data
munging. This works for me:

dim entry as new DirectoryEntry("LDAP://yourdn here")
dim pwd as object = entry.Properties("pwdLastSet").Value
dim pwdDate as DateTime
pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger( pwd))

Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64

dim low as int32
dim high as int32
dim valBytes(7) as byte

dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger)
low = longInt.LowPart
high = longInt.HighPart

BitConverter.GetBytes(low).CopyTo(valBytes, 0)
BitConverter.GetBytes(high).CopyTo(valBytes, 4)

Return BitConverter.ToInt64(valBytes, 0)

End Function
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface

Note that you can also get the high and low values via reflection and late
binding or by importing the activeds.dll COM object into .NET.

Note that the DateTime you get back will be in Utc, so if you need local
time, make sure you call ToLocalTime.

HTH,

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
Hello there
I need to get the "PwdLastSet" of a user object to know when he last set
his
password.
I am using DirectoryServices.DirectoryEntry to bind to the user object,
but
it either gives "Argument 'Prompt' cannot be converted to type 'String'." or
when I use .tostring it returns "system._comobject"
I even tried to use this line but it also failed
dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast from
type '_ComObject' to type 'Long' is not valid.
I use the code below:
Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://cn=sameh
ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject" '
"Argument 'Prompt' cannot be converted to type 'String'."
Any ideas?
Thanks in advance
Sameh


Nov 21 '05 #4

P: n/a
Thanks a lot for your reply

"Jared" <as***********@nospam.com> wrote in message
news:10*************@corp.supernews.com...
I think the pwdlastset attribute is a concatenated version of two distinct
dates. I did a quick search for pwdlastset and came across this vbscript
block. You can get some ideas from this.

http://www.rlmueller.net/Programs/PwdLastSet.txt
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
Hello there
I need to get the "PwdLastSet" of a user object to know when he last set
his
password.
I am using DirectoryServices.DirectoryEntry to bind to the user object,
but
it either gives "Argument 'Prompt' cannot be converted to type 'String'." or
when I use .tostring it returns "system._comobject"
I even tried to use this line but it also failed
dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast from
type '_ComObject' to type 'Long' is not valid.
I use the code below:
Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://cn=sameh
ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
"system._comobject"
MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject" '
"Argument 'Prompt' cannot be converted to type 'String'."
Any ideas?
Thanks in advance
Sameh


Nov 21 '05 #5

P: n/a
You need to import the System.Runtime.InteropServices namespace in order to
get those attribute definitions.

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dear Joe
Thanks for replying
as i am totaly new to the develeopment field i tried to understand the
code
that you sent.
But after a long time i decided to copy it to my form and see what happens
this part (that i failed to understand)
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface IADsLargeInteger
Property HighPart() As Int32
Property LowPart() As Int32
End Interface

fails with the following errors:

Attribute cannot be used on 'IADsLargeInteger'.
Type 'ComImport' is not defined.
Type 'InterfaceTypeAttribute' is not defined.

i would rerall appriciate it if you tell me what i should do .
thanks again

"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:e0**************@tk2msftngp13.phx.gbl...
There are basically two ways to get the Int64 value you need.

If you use the DirectorySearcher, it marshals AD INTEGER8 types to .NET
Int64 automatically, so no work needs to be done. This is by far the
easiest way.

If you use the DirectoryEntry, it marshals the value as an ADSI
IADsLargeInteger type, which at runtime is a System.__ComObject. This is
annoying, but you can get the value with a little interop and some data
munging. This works for me:

dim entry as new DirectoryEntry("LDAP://yourdn here")
dim pwd as object = entry.Properties("pwdLastSet").Value
dim pwdDate as DateTime
pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger( pwd))

Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64

dim low as int32
dim high as int32
dim valBytes(7) as byte

dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger)
low = longInt.LowPart
high = longInt.HighPart

BitConverter.GetBytes(low).CopyTo(valBytes, 0)
BitConverter.GetBytes(high).CopyTo(valBytes, 4)

Return BitConverter.ToInt64(valBytes, 0)

End Function
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface

Note that you can also get the high and low values via reflection and
late
binding or by importing the activeds.dll COM object into .NET.

Note that the DateTime you get back will be in Utc, so if you need local
time, make sure you call ToLocalTime.

HTH,

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
> Hello there
> I need to get the "PwdLastSet" of a user object to know when he last
> set
> his
> password.
> I am using DirectoryServices.DirectoryEntry to bind to the user object,
> but
> it either gives "Argument 'Prompt' cannot be converted to type 'String'." > or
> when I use .tostring it returns "system._comobject"
> I even tried to use this line but it also failed
> dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast
> from
> type '_ComObject' to type 'Long' is not valid.
> I use the code below:
> Dim entry As New DirectoryServices.DirectoryEntry
> entry.Path = "LDAP://cn=sameh
> ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
> MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine
> MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
> "system._comobject"
> MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
> "system._comobject"
> MsgBox(entry.Properties("pwdlastset").Value) 'returns "system._comobject" > '
> "Argument 'Prompt' cannot be converted to type 'String'."
> Any ideas?
> Thanks in advance
> Sameh
>
>



Nov 21 '05 #6

P: n/a
Thanks
worded perfectly
"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote
in message news:Or*************@TK2MSFTNGP11.phx.gbl...
You need to import the System.Runtime.InteropServices namespace in order to get those attribute definitions.

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dear Joe
Thanks for replying
as i am totaly new to the develeopment field i tried to understand the
code
that you sent.
But after a long time i decided to copy it to my form and see what happens this part (that i failed to understand)
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface IADsLargeInteger
Property HighPart() As Int32
Property LowPart() As Int32
End Interface

fails with the following errors:

Attribute cannot be used on 'IADsLargeInteger'.
Type 'ComImport' is not defined.
Type 'InterfaceTypeAttribute' is not defined.

i would rerall appriciate it if you tell me what i should do .
thanks again

"Joe Kaplan (MVP - ADSI)" <jo*************@removethis.accenture.com> wrote in message news:e0**************@tk2msftngp13.phx.gbl...
There are basically two ways to get the Int64 value you need.

If you use the DirectorySearcher, it marshals AD INTEGER8 types to .NET
Int64 automatically, so no work needs to be done. This is by far the
easiest way.

If you use the DirectoryEntry, it marshals the value as an ADSI
IADsLargeInteger type, which at runtime is a System.__ComObject. This is annoying, but you can get the value with a little interop and some data
munging. This works for me:

dim entry as new DirectoryEntry("LDAP://yourdn here")
dim pwd as object = entry.Properties("pwdLastSet").Value
dim pwdDate as DateTime
pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger( pwd))

Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64
dim low as int32
dim high as int32
dim valBytes(7) as byte

dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger) low = longInt.LowPart
high = longInt.HighPart

BitConverter.GetBytes(low).CopyTo(valBytes, 0)
BitConverter.GetBytes(high).CopyTo(valBytes, 4)

Return BitConverter.ToInt64(valBytes, 0)

End Function
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface

Note that you can also get the high and low values via reflection and
late
binding or by importing the activeds.dll COM object into .NET.

Note that the DateTime you get back will be in Utc, so if you need local time, make sure you call ToLocalTime.

HTH,

Joe K.

"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
> Hello there
> I need to get the "PwdLastSet" of a user object to know when he last
> set
> his
> password.
> I am using DirectoryServices.DirectoryEntry to bind to the user object, > but
> it either gives "Argument 'Prompt' cannot be converted to type

'String'."
> or
> when I use .tostring it returns "system._comobject"
> I even tried to use this line but it also failed
> dater.FromFileTimeUtc(entry.Properties("pwdlastset ").Value) 'ast
> from
> type '_ComObject' to type 'Long' is not valid.
> I use the code below:
> Dim entry As New DirectoryServices.DirectoryEntry
> entry.Path = "LDAP://cn=sameh
> ahmed,ou=infrastracture,ou=masreya,dc=masreya,dc=l ocal"
> MsgBox(entry.Properties("homedirectory").Item(0).T oString) 'works fine > MsgBox(entry.Properties("pwdlastset").Item(0).ToSt ring) 'returns
> "system._comobject"
> MsgBox(entry.Properties("pwdlastset").Value.ToStri ng) 'returns
> "system._comobject"
> MsgBox(entry.Properties("pwdlastset").Value) 'returns

"system._comobject"
> '
> "Argument 'Prompt' cannot be converted to type 'String'."
> Any ideas?
> Thanks in advance
> Sameh
>
>



Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.