Page 2 of 2 <12
Topic Options
#115210 - 2004-03-01 03:52 AM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Radimus:

Sorry - I know you were proud of that code snippet, but it keeps returning an 87 error.. I replaced it with the original code and now it works fine. Your logic looks reasonable - I don't know why the error is coming back.
Code:
 
For Each $objInstance in $objEnum
If $objInstance
$ = Execute(Chr(36) + 'sValue = ' + Chr(36) + 'objInstance.' + $sWhat)
; $tmp = $tmp +'|' + iif(VarType($sValue) & 8192,join($sValue,'|',ubound($sValue)),$sValue)
if VarType($sValue) & 8192
For Each $sItem in $sValue
$Tmp = $Tmp + '|' + Trim($sItem)
Next
else
$Tmp = $Tmp + '|' + Trim($svalue)
Endif
EndIF
Next



The script where I'm using this is very large (8600+ lines to date) and has extensive error checking. The intermediate calling UDF was seeing the 87 error come back and created an empty array to return to the main routine.

Both the secure (with credentials) and unsecure forms are now returning data properly without error. As I said - the UDF always returned the proper data, but something in the IIF and JOIN was generating an error 87, which was being returned by the UDF.

NTDoc and I had some serious challenges using IIF last week - the only way we were able to resolve it was to code the traditional If/Else/EndIf. I think IIF is buggy when you place functions or statements in the returned values.

You could probably replace the For/Each with the Join, but I haven't seen an array returned by anything I query, so I don't have a way to test it.

Anyway, I'd be happy if you update your WMIQuery post with the security now that it works, and I'll delete this post (or the moderator could move it to Scripts) for further discussion on the IIF issue.

Glenn

_________________________
Actually I am a Rocket Scientist! \:D

Top
#115211 - 2004-03-01 07:26 AM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
glenn, you seem to have habit of replacing rather than investigating...
looking at the line, there should be easy way to see what causes the error.
and I think it's simply that non-array parameter is passed, thus:
join($sValue,'|',ubound($sValue))

will become:
join("mystring","|",ubound("mystring"))

and yet:
join("mystring","|",-1)

doh, as count, join does not allow negative numbers, that causes the error.
_________________________
!

download KiXnet

Top
#115212 - 2004-03-01 01:17 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
before that executes, it checks to see if the string is an array

iif(VarType($sValue) & 8192,join($sValue,'|',ubound($sValue)),$sValue)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#115213 - 2004-03-01 01:33 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
If you read my post, you'd have seen I was short on time last night. I was reporting that Radimus' change was returning an error even when it worked. I broke the code down line by line to determine that the statements within the IIf were working properly - hence the If/Else/Endif.

Also - it was Radimus' change - I restored his original code just to show it worked before. The problem appears to be in the IIf, since breaking it out to an If/Else/Endif works... I have since updated the code to use the join statement and it STILL works as long as the IIf isn't used.

Even though the IIf is returning the correct data, when you check the exit code, it is failing - the individual statements within the code are working just fine.

At this point, based on this and the challenges that NTDoc and I had the other night, it appears that IIF does not work exactly like an If/Else/Endif statement.. If you test and return values, it is fine, but if you test and return results of other statements that might be invalid WHEN they should not be executed (the purpose of the IF) you get an error, or the IIF returns strange data. I'm not sure if we're pushing the design limits of IIF, but I won't use it moving forward to return statement results. I've been "burned" a number of times.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#115214 - 2004-03-01 04:13 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I'm beginning to think that the IIF statement evaluates both TRUE and FALSE statements before determining the state of the IF!

If I add the following code:
Code:

$zz = iif(VarType($sValue) & 8192, 'Array', 'Var')
'zz=' $zz ' : ' @SERROR ?


It completes successfully and prints the appropriate type.

Code:

$zz = iif(VarType($sValue) & 8192, UBound($sValue), 'Var')
'zz=' $zz ' : ' @SERROR ?


It completes successfully and displays the expected values.

However, if I change it to:
Code:

$zz = iif(VarType($sValue) & 8192, Join($sValue, '|', UBound($sValue)), 'Var')
'zz=' $zz ' : ' @SERROR ?


It returns the error 87. As Lonk pointed out, UBound returns a "-1" when it is a simple string, which would be invalid IF the statement is executed - which you would believe it isn't.

So, it appears that the current implementation of IIF can't be used to return values from statements if they might be invalid under any condition!

I wonder if this should be addressed with Ruud?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#115215 - 2004-03-01 04:45 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Glenn:

Yes, IIF will process both the TRUE and FALSE return expressions, which can lead tor problems. I tend to only use IIF() if the two return expressions are static variables and not functions.

This behavior has already been discussed extensively in the following thread: iif() stack overflow exception "problem"?
_________________________
There are two types of vessels, submarines and targets.

Top
#115216 - 2004-03-01 06:05 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Well, apparently Radimus, NTDoc, and I all missed that discussion!

I'll leave it as it stands and up to Radimus to decide if he wants a separate UDF or is willing to update his UDF - without the IIF clause.

Regardless, this post should probably be moved to the Scripts forum now, given the number of revisions and amount of discussion.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#115217 - 2004-03-01 09:07 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Yep, I missed that thread. Glad to see I was not going crazy after all.

As far as the discussion goes... we used to be very strict about it, but along the way we relaxed the rules and agreed that it would be okay to discuss the UDF. Since the discussion is about the UDF and or pieces of it I see no need to move this thread Glenn.

Thanks Jens for posting a link to that thread on IIF

Top
#115218 - 2004-03-01 09:14 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Ron:

I suggested moving this thread <if> Radimus agrees to include the authentication in his base UDF. If he does, there's no need for this to exist in the UDF forum, and it might even confuse things being here. If he doesn't, I'll repost and re-title this post with the last working version.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#115219 - 2004-03-01 09:29 PM Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
go ahead and move it... I'll fix the UDF and post it there
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 493 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.066 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org