#47474 - 2003-10-31 12:56 AM
Problems with value returned by WMIQuerry
|
Sverre
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
|
|
|
|
#47477 - 2003-10-30 03:08 PM
Re: Problems with value returned by WMIQuerry
|
Radimus
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
|
|
Top
|
|
|
|
#47478 - 2003-10-30 03:18 PM
Re: Problems with value returned by WMIQuerry
|
Sverre
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.
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
|
|
|
|
#47480 - 2003-10-30 03:29 PM
Re: Problems with value returned by WMIQuerry
|
Richard H.
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
Getting the hang of it
Registered: 2002-09-29
Posts: 52
|
code:
c:\mrtg\bin\kix32 c:\mrtg\bin\print.kix
|
|
Top
|
|
|
|
#47483 - 2003-10-30 04:28 PM
Re: Problems with value returned by WMIQuerry
|
Sverre
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
|
|
|
|
#47485 - 2003-10-30 04:36 PM
Re: Problems with value returned by WMIQuerry
|
Sverre
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|