#115210 - 2004-03-01 03:52 AM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
Glenn Barnas
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!
|
Top
|
|
|
|
#115211 - 2004-03-01 07:26 AM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
Lonkero
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
   
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)
|
Top
|
|
|
|
#115213 - 2004-03-01 01:33 PM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
Glenn Barnas
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!
|
Top
|
|
|
|
#115214 - 2004-03-01 04:13 PM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
Glenn Barnas
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!
|
Top
|
|
|
|
#115217 - 2004-03-01 09:07 PM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
NTDOC
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
|
|
|
|
#115219 - 2004-03-01 09:29 PM
Re: WMIQuery + WMIAuthenticate = WMI_Auth_Query!
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
go ahead and move it... I'll fix the UDF and post it there
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2562 anonymous users online.
|
|
|