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