ADSI query problem with VBS

I am an intern at a major corporation and one of the assignments one of my co-workers decided to direct my way was to make pre-existing VBScript return the neccesary values from an ADSI query.

I am not very familiar with ADSI or LDAP so bear with me if I dont make any sense, and I will try to clarify on any points needed.

This script, when handed to me, worked as is. It got the appropriate values and displayed them in a vbs popup box. Fine.

The problem lied in that the co-worker who assigned this to me could not get it to display 2 extra variables that he wanted included in the query.

The problem appears to lie in the variable type, which is reported as a Long/Interval by the program that he used to display the information locally on the machine.

The query works fine without producing any errors (including the variables in question in the query string is no problem). The problem comes when trying to assign those variables (part of an object) to another variable or trying to display the contents. VBS gives me an error.

I found this odd, so I decided to use the vartype() function to display the types of the variables. The data that was working all returned as the proper type (string, int, what have you). However the data in question, when ran through the vartype() function, reports the variable as type 9 (objects). I found this extremely odd, and I find it safe to say that this is where my problem lies. (of course I cannot assign an object to a normal variable or simply print the object)

Is the query supposed to serve up that variable type as something that would be identificable as an object to VBS? If so, is there a way to convert or process this? Or does this represent some sort of error or problem on the server side, and dosent actually deal with the script at all?

FYI, the variables in question are Long/Interval types that reprsent the data of a users lastlogon date and another data (forget what it corresponds to) that is in the format of a Unix date/time (Unix epoch zeroed).

Thanks for any help you might offer, and I hope my inexperience hasnt butchered the question beyond help. The code in question should be attached to this message as a .vb file. Simply rename the file to .vbs to test or just view in notepad. (.vbs wasnt a valid extension)
[2378 byte] By [JRosensteel] at [2007-11-18 22:57:32]
# 1 Re: ADSI query problem with VBS
Try using the cDate() function when you try to display the last logn date and the pswd last set date.

WScript.Echo name & ";" & samAccountName & ";" & whenCreated & ";" & cDate(logonLast} & ";" & cDate(lastpwd) & ";" & vartype(objuser.PwdLastSet)

I seem to think that these are stored as a DATE data type.

That may be what you are running into.

HTH
f1shrman at 2007-11-10 3:39:14 >
# 2 Re: ADSI query problem with VBS
Thanks for the help, however your suggestion dosent seem to be helping. I included this portion of code:

WScript.Echo name & ";" & samAccountName & ";" & whenCreated & ";" & cDate(objuser.lastLogon) & ";" & cDate(objuser.PwdLastSet)

And Windows Script Host returned the following error:
Error: Object dosen't support this property or method.
JRosensteel at 2007-11-10 3:40:13 >
# 3 Re: ADSI query problem with VBS
I really did not look at this code earlier, but I don't see where you are setting the values for logonLast and lastpwd.

Are you doing the same as you are for these three?

whenCreated = objUser.whenchanged
name = objuser.displayName
samAccountName=objuser.sAMAccountName

Or are you referencing them from the recordset object that was returned from the search.

I did a little looking and this link has a really good example of how to get the last login value. http://www.developersdex.com/asp/message.asp?p=&r=4010441&Page=1

This word doc may give you few ideas as well - www.giac.org/practical/Brad_Sanford_GCNT.doc

HTH
f1shrman at 2007-11-10 3:41:15 >
# 4 Re: ADSI query problem with VBS
Are you doing the same as you are for these three?

whenCreated = objUser.whenchanged
name = objuser.displayName
samAccountName=objuser.sAMAccountName

Or are you referencing them from the recordset object that was returned from the search.

I tried including a working version of the code. Since the code did not begin to break until I tried referencing the recordset object (either by assigning to variable or directly echo-ing them), I did not include that portion.

Anyways, thanks for the links, I will take a look at what they say.
JRosensteel at 2007-11-10 3:42:20 >