Page 1 of 2 12>
Topic Options
#111653 - 2004-01-12 08:41 PM Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

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

I'm having a strange problem with a large KixForms project. The tool queries a remote server via registry info and WMI and displays it in a form. One function reboots the server, monitoring it as it shuts down and restarts. When the server is back up ("up" = responds to ping, then returns an "xnet list" with no "start pending" results), the form is cleared and the function that queries the target and updates the form is called. At this point, the script exits with the following message:

Code:
 
ERROR : unexpected command!
Script: D:\dev\SIT\smit.kxw
Line : 954



If I comment out the clear/re-query function calls, no error occurs. Also, if I query another server, it succeeds. However, if I then query the server that was rebooted, the error occurs!

The line being referenced is the first of the WMIQuery() series of function calls.
Code:
 
$HW_00 = WMIQuery('Manufacturer', 'Win32_ComputerSystem', $System)[0]


I'm at a loss as to why this function works the first time, works multiple times, works on another server after a reboot of a target, but fails any time a server rebooted via the tool reruns the query.

I'd post the code, but at 125K, it's a bit challenging. I'll zip/email it to anyone that wants to play with it, but I'm really wondering if there's something I'm missing with how WMI works, or possibly not properly clearing a WMI connection??

Thanks in advance,

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

Top
#111654 - 2004-01-12 09:38 PM Re: Odd error in KixForms app
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Is it possible that WMI is not yet started up on the remote computer? Can you delay the WMI query by e.g. a couple of minutes to verify that or check whether WMI has started before issuing a WMIQuery() ?
_________________________
There are two types of vessels, submarines and targets.

Top
#111655 - 2004-01-12 10:32 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

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

Thanks for the thoughts... I considered that - and dismissed it - here's why:

I have a function called HWInfo() - it returns an array of values collected from WMI. This function is called in the project to populate the form. I have another script called HWI, which simply calls HWInfo and displays all the array values. When I pause the project script and run HWI from a command line, it returns appropriate values. When I click OK on the MessageBox and let the project script continue, it dies. That's why I thought it might be the way I was referencing things or not clearing a variable properly. Should I formally close the WMI connection somehow?

Also, I use the Kix shutdown command to start the reboot.. Then I go into a loop pinging the server every 2 seconds until it fails to respond, then continue until it begins to respond again.. then another loop executing 'XNET LIST \\server | Find "Pending" ' every 5 seconds. When no output is returned from this command, all services are "ready" and I then wait 10 seconds before querying. (This is when the MB pops up and I can successfully run HWI).

Anyway, I think I'm waiting long enough to start..

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

Top
#111656 - 2004-01-12 10:52 PM Re: Odd error in KixForms app
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

Should I formally close the WMI connection somehow?





That would be my guess. If you end (and rerun) the script rather than pause it, do you get the same results?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111657 - 2004-01-12 11:59 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
No - exiting the script and re-running it works. But - so does simply selecting a different computer! I'm thinking I have a problem in the WMIQuery udf that I downloaded.. I've turned on NoVarsInStrings and Explicit options, and when I regen any scripts that use the WMIQuery function, I get similar failures.. Looking into this more deeply now.

Already changed the $=Execute("$$...") line to use single "$" chars, and put the last var outside the string. That helped my small test function, so I think I'm on the right track.

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

Top
#111658 - 2004-01-13 12:32 AM Re: Odd error in KixForms app
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Of course NoVarsInStrings will affect the Execute('$$...) thing. This is well documented.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111659 - 2004-01-13 04:02 AM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Yes, it is..

I didn't realize that was the problem - I had to dig through the code. I downloaded and used WMIQuery pretty much as-is, and it had worked very well until this project.

So, now - what do I do? It's a moral dilemma, no?

Do I modify the function to support NoVarsInStrings? Won't that cause scripts that don't specify this to fail? Or - do I check the NoVar setting on entry to the function, turn it off, then restore it before exiting the function?

Or - creative coding:
Code:

; Get setting
$RC = SetOption('NoVarsInStrings', 'On')
; Define "$" or "$$"
$Dollar = IIf($RC = 'On', '$', '$$')
; Restore setting
$RC = SetOption('NoVarsInStrings', $RC)
; Define EXE string
$EXE = $Dollar + 'Varname'
Execute $EXE



Granted, there are only a handful of functions that utilize the Execute statement, but its something to consider as my function library grows, and I grow more dependent on it.

Whadda ya think?

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

Top
#111660 - 2004-01-13 04:21 AM Re: Odd error in KixForms app
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I would say that if there is code in a UDF that can fail if NoVarsInStrings is on, then you should both modify the code to work with NoVarsInStrings on and add checks for the status of NoVarsInStrings to make sure that modified code works as expected.

See this topic for one of several discussions we've had.
SetOption options for UDFs
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111661 - 2004-01-13 04:33 AM Re: Odd error in KixForms app
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Here is another
New FAQ Topic: Using $ inside quotes
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111662 - 2004-01-13 04:49 AM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

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


Just re-genned my script after modifying the WIMexec() code and the reboot process worked.

So, here's the odd thing - why did it work every time and then fail after a reboot? If it was really the "$$var" issue, then wouldn't it have failed all along? I just find the failure odd and inconsistent..

Thanks for brainstorming, and I'll review the links for other ideas on strengthening the library.

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

Top
#111663 - 2004-01-16 02:17 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Found a really simple solution to using NoVarsInStrings along with the Execute function that does not depend on the state of NoVarsInStrings - This example is how I fixed the WMIExec function.

Code:
 
Dim $Dollar, $exCmd ...
$Dollar = Chr(36)

$exCmd = $Dollar + "sValue = " + $Dollar + "objInstance." + $sWhat
$ = Execute($exCmd)


As you can see, the $exCmd string is built using the $Dollar value (outside strings) preceeding the name of any variable that must be referenced by the Execute function. It also pre-references the $sWhat, inserting the value into the statement, rather than letting the Execute statement reference it.

I've tested this mod with both NoVarsInStrings settings and it works either way. It's a bit long, but it eliminates all the logic and preparatory code.

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

Top
#111664 - 2004-01-16 03:10 PM Re: Odd error in KixForms app
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Ah, so you discovered how to adapt the following FAQ: Proper use of quotes to the $-sign case. However, I still think that NoVarsInStrings=ON should be a KiXtart/KiXforms Best Practice (KBP).
_________________________
There are two types of vessels, submarines and targets.

Top
#111665 - 2004-01-16 08:38 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Yeah, well - Les says tomato, I say tomatoE!

It's just another way to skin the same kat, but to me, referencing the $Dollar instead of the $Quote was more obvious when reading it later.

I agree on the KBP, which is why I'm testing every one of my functions in the lib to operate correctly with EXPLICIT and NoVarsInStrings both ON and OFF.

I am, however, back to my original problem. It worked at home, restarting a 2K3 server from an XP workstation, but at the office, restarting a 2K3 server from a 2K workstation fails with the same error message.

I'm rewriting the code to focus on two components - collecting information from the remote server, and tracking the reboot of the server, and eliminating all extraneous code.

What's wierd is that the information is collected once and displayed. Then, after issuing a reboot and monitoring the loss and restoration of Ping response, and then insuring that we can really communicate with the NetBIOS process, we repeat the entire data collection and display function. When the data is displayed, it fails.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#111666 - 2004-01-17 04:02 PM Re: Odd error in KixForms app
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
weird...
this really sounds like wmi-cache issue. given that I didn't bother looking at wmiQuery UDF.
_________________________
!

download KiXnet

Top
#111667 - 2004-01-17 07:26 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
OK, different words, but that's the kind of thing I suspected in my first post. Is there some way to close / clear the cache?

Keep in mind, if I put a pause statement into the failing code just prior to the HWI() function (which calls WMIQuery repeatedly), and run a script that calls HWI() and just displays the results, it works. Separate environment and session, but it proves that the server responds to the HWI function. Allow the main prog to continue and it dies when trying to display the results of the HWI.

Further, if I comment out the code to re-query the server and then select another server, everything works, but if I then query the rebooted server, it fails with the same error.

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

Top
#111668 - 2004-01-18 01:31 AM Re: Odd error in KixForms app
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I think I saw a document discussing this or similar thing...
will see if I find...
_________________________
!

download KiXnet

Top
#111669 - 2004-01-18 02:05 AM Re: Odd error in KixForms app
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, found something but according to it, this should not happen.
dude, you can mail it to me...
will have a quickie at it.
_________________________
!

download KiXnet

Top
#111670 - 2004-01-18 04:52 AM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Thanks, I'll do that if the last mods don't clear it up.

I had one function that collected the data and updated the form. I started breaking it into two functions - one to collect the data and store it in a set of global arrays, and another to populate the form with the array data. I figured this way, I could more easily narrow down where the error is actually occurring, rather than where it is being presented. If I can get the code cleaned up again before I leave for skiing tomorrow (yes, I do get away from coding every so often), I'll shoot it out to you. Otherwise, look for it on Tues.

Regards!

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

Top
#111671 - 2004-01-20 08:59 PM Re: Odd error in KixForms app
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
SOLVED!!!

I was calling a HWInfo() function, which made several calls to WMIQuery(). It seemed to be failing consistently when calling the first WMIQuery function call (of about 12) in the HWInfo function. The HWInfo func only needed the first element of the array that WMIQuery was returning, so I wrote the code as:

Code:
 
$HW_01 = WMIQuery(long_string_of_stuff)[0]

; later...

$HWInfo = $HW_01, $HW_02 ...



I modified the HWInfo function to accept the entire array and then return just the first element:
Code:
 
$HW_01 = WMIQuery(long_string_of_stuff)

; later...

$HWInfo = $HW_01[0], $HW_02[0] ...



This now works.

What drove me nuts is that the first form worked until a server was queried, rebooted, and queried again from the same script instance. (the script itself invoked the remote reboot of the server).

OK - so now I know WHAT, but can anybody clue me in as to WHY??

Thanks!

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

Top
#111672 - 2004-01-21 08:22 AM Re: Odd error in KixForms app
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
don't wanna pass that part of the code?
old and new version...
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1179 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.116 seconds in which 0.068 seconds were spent on a total of 13 queries. Zlib compression enabled.

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