Page 1 of 1 1
Topic Options
#47474 - 2003-10-31 12:56 AM Problems with value returned by WMIQuerry
Sverre Offline
Getting the hang of it

Registered: 2002-09-29
Posts: 52
If I run the following script the value returned in $jobs isn't accepted by MRTG. But if I remove the lines from $workstation.... to :ok it works ok.

So my guess is that the value $jobs gets when running this script isn't acceptable. I've tried converting it with cstr(), cint(), value() and the result isn't accepted anyway. I've tried to check the variable with vartype() and the value returned is the same as the one returned from another script I'm running (that works).

Any ideas?

code:
  
Break ON
$gNull=SetOption("ASCII","ON")
$gNull=SetOption("WrapAtEOL","ON")
$jobs = 0

$workstation = "lorfile"
$x = 0
$name = "Something"
while len($name) > 0
$name = WMIQuery("Name","Win32_PerfRawData_Spooler_PrintQueue",$workstation)[$x]
if $name = "_Total"
$jobs = WMIQuery("TotalJobsPrinted","Win32_PerfRawData_Spooler_PrintQueue",$workstation)[$x]
goto ok
endif
$x = $x + 1
loop

:ok

$jobs
?
$jobs
?
"test1"
?
"test2"
?

Exit 0



;SYNTAX WMIQuery($what,$from,optional $computer,optional $where, optional $x)
; http://download.microsoft.com/download/platformsdk/wmicore/1.5/W9XNT4/EN-US/wmicore.EXE

FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x)
Dim $sQuery, $objEnum, $sValue, $sItem, $lUbound
Dim $aTMP[0]
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If Not $sComputer
$sComputer=@WKSTA
EndIf
If $sWhere AND $x
$sQuery = $sQuery + " Where " + $sWhere + " = '"+$x+"'"
EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//"+$sComputer)
If @ERROR
Exit VAL("&"+Right(DecToHex(@ERROR),4))
Return
EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR
Exit VAL("&"+Right(DecToHex(@ERROR),4))
Return
EndIf
For Each $objInstance in $objEnum
If $objInstance
$=Execute("$$sValue = $$objInstance.$sWhat")
Select
Case VarType($sValue) & 8192
For Each $sItem in $sValue
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sItem)
Next
Case 1
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sValue)
EndSelect
EndIf
Next
$WMIQuery = $aTMP
Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION


Top
#47475 - 2003-10-30 01:05 PM Re: Problems with value returned by WMIQuerry
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
What do you see whe you place DEBUG ON on top off your script?

What kix version do you use?
_________________________
Co


Top
#47476 - 2003-10-30 02:49 PM Re: Problems with value returned by WMIQuerry
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
little hard to say anything without seeing the values.
_________________________
!

download KiXnet

Top
#47477 - 2003-10-30 03:08 PM Re: Problems with value returned by WMIQuerry
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
code:
 
break on
$gNull=SetOption("ASCII","ON")
$gNull=SetOption("WrapAtEOL","ON")

$jobs = 0
$workstation = "lorfile"

$jobs = WMIQuery("TotalJobsPrinted","Win32_PerfRawData_Spooler_PrintQueue",$workstation,"Name",'_Total')[0]

? $jobs

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#47478 - 2003-10-30 03:18 PM Re: Problems with value returned by WMIQuerry
Sverre Offline
Getting the hang of it

Registered: 2002-09-29
Posts: 52
Nice one, that cuts the run time dramatically. Unfortunately it doesn't fix the problem. [Smile]

Here is the output I get if I run the script and pipe the output to a file:
code:
582
582
Script error: failed to find/open script!


Why do I get the Script error:...?

Top
#47479 - 2003-10-30 03:26 PM Re: Problems with value returned by WMIQuerry
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
how do you call this script?
_________________________
!

download KiXnet

Top
#47480 - 2003-10-30 03:29 PM Re: Problems with value returned by WMIQuerry
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
KiXtart can run multiple scripts, e.g.
code:
kix32.exe script1.kix script2.kix

Will run both script1.kix and script2.kix. You probably have something extra on your command line.
code:
kix32.exe script.kix somegarbage >output.txt

Will run script.kix successfully, and then complain it cannot "open/find the script" when it tries to execute "somegarbage".

Top
#47481 - 2003-10-30 03:29 PM Re: Problems with value returned by WMIQuerry
Sverre Offline
Getting the hang of it

Registered: 2002-09-29
Posts: 52
code:
c:\mrtg\bin\kix32 c:\mrtg\bin\print.kix


Top
#47482 - 2003-10-30 04:15 PM Re: Problems with value returned by WMIQuerry
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please remove the GOTOs in your code with better constructs.

You can also use the eventlog to gather print information. See e.g. Printmonitor - counts the paper usage on printers in a network (updated for SQL DB)
_________________________
There are two types of vessels, submarines and targets.

Top
#47483 - 2003-10-30 04:28 PM Re: Problems with value returned by WMIQuerry
Sverre Offline
Getting the hang of it

Registered: 2002-09-29
Posts: 52
I need something that works with MRTG as that is the program we use to monitor our network.

In MRTG you can add external data collectors to retrieve stuff not easily done with SNMP (this should work like a breeze with SNMP, but SNMP isn't working very good on W2K server and the add on program I use can't read the print ques correctly). So I make a small Kixtart script that finds what I need in WMI.

The only problem here is that for some strange reason it looks like Perl tries to run not only the kix script, but also something else. This "something else" then makes Kix32 return the string "Script error: failed to find/open script!
" (this is the one I see when I pipe the output in DOS mode, while when Perl runs I get this error in the log "Script error: unknown or unexpected command []!".

Top
#47484 - 2003-10-30 04:32 PM Re: Problems with value returned by WMIQuerry
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Does the KiXtart script run on it's own when not called from Perl?
_________________________
There are two types of vessels, submarines and targets.

Top
#47485 - 2003-10-30 04:36 PM Re: Problems with value returned by WMIQuerry
Sverre Offline
Getting the hang of it

Registered: 2002-09-29
Posts: 52
No problem running it outside of Perl. Thats when it return the error: "Script error: failed to find/open script! ".

You don't see this error when you run it, you just see the output as it should be. But if you pipe the result like this:

code:
kix32 test.kix > test1.txt 2 > test2.kix

You will find the error code in test2.txt together with the output it should give.

I've placed @error all over the script, including the WMIQuery function, and nowhere does it return any errors.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.062 seconds in which 0.026 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