#125281 - 2004-08-18 07:51 PM
Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
OK.. I am feeling a little lame here.. It seems that vars for computer name for WSHPING, WMIQUERY do not pass through right. What am I doing wrong?
Trying to run the following: Code:
cls break on DIM $oxl,$Row,$b,$ip,$make,$model,$sn,$cs,$mm,$mt,$,$u $rc=SETOPTION('Explicit','On') $rc=SETOPTION('NoVarsInStrings','On')
$oXL=Createobject('Excel.application') ;Check to insure that Excel is available IF 0<>@error ?@error ' Excel Application is not found' SLEEP 4 RETURN ENDIF $Rc=$oXL.workbooks.open(@scriptdir+'\Altiris.xls') $Row=1 ;Row to start at using column headings, change to 0, if needed WHILE $oXL.cells($Row,1).value<>'' ;need a value each time in column 1 $Row=$Row+1 IF $oXL.cells($Row,1).value='' ;Once it gets to a blank row... $oXL.quit ;quit Excel $oXL=0 ;set the object to 0 ELSE $b=$oXL.cells($Row,1) $ip=WSHPing($b) $u=WMIQuery("username","Win32_ComputerSystem",$b) ;$ip=WSHPing('"'+$b+'"')[0] $make=WMIQuery("Manufacturer","Win32_ComputerSystem",$b) ;$make = WMIQuery("Manufacturer","Win32_ComputerSystem",'$b')[0] ;$model=WMIQuery("Model","Win32_ComputerSystem",'$b')[0] ;$sn=WMIQuery("SerialNumber","Win32_BIOS",'$b')[0] ;$cs=WMIQuery("CurrentClockSpeed","Win32_Processor",'$b')[0] ;$mm=WMIQuery("MonitorManufacturer","Win32_DesktopMonitor",'$b')[0] ;$mt=WMIQuery("MonitorType","Win32_DesktopMonitor",'$b')[0] ?$b ?$ip[0] ?$u[0] ?$make
;IF LEFT($ip,5)='10.55' ;?$b+','+$ip ;ENDIF ENDIF LOOP ?'process is complete' get $
FUNCTION WSHPing($Computer,optional $replies) dim $ip, $l, $r, $count, $return, $line ,$pos, $avg,$shell if not $replies $replies=1 endif $ip=$computer $Count=0 $shell='%comspec% /c %windir%\system32\ping $Computer -n $replies ' $return=WSHPipe($shell,1) if not @error for each $line in $return select case instr($line,"[") $l=instr($line,"[")+1 $r=instr($line,"]") $ip=substr($line,$l,$r-$l) case instr($line,"reply from") $Count=$Count+1 case instr($line,"Average") $pos=instr($line,"Average")+8 $avg=val(right("$line",len($line)-$pos)) endselect if instr($line,"timed out") $Count=$Count-1 endif next $WSHPing=$ip,$count,$avg else $WSHPing="0.0.0.0","0","0" exit(487) endif ENDFUNCTION
Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode,$WshErrorMsg $WshErrorMsg="" $WshShell=CreateObject("WScript.Shell") $oExec=$WshShell.Exec($ShellCMD) While $Exit<>1 Dim $Output Select Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll $WshErrorMsg = $Output Case 1 $Output=-1 EndSelect If $Output=-1 If $oExec.Status=1 $Exit=1 Endif Else If $NoEcho<>1 ? $Output Endif $AllOutput = $AllOutput + $Output Endif Loop $WshExitCode=$oExec.ExitCode $WshPipe=split($AllOutput,chr(10)) Exit($WshExitCode) EndFunction
;Function LOGGER($logfil,$logdat) ; ;Author Kent Dyer (leptonator@hotmail.com) ; ;Contributors MBrecht on CramSession.com ; http://infocenter.cramsession.com/TechLibrary/GetHtml.asp?ID=721&GetDes=&CatID=293 ; "Create Loginlog" ; Jooel (Lonkero) - Code cleanup ; Howard Bullock ; ;Action Writes to a Server Log ; ;Syntax LOGGER($logfile,$logdata) ; ;Version 1.2 - Recommendation by Howard Bullock ; 1.1 - Clean-up by Lonkero ; ;Parameters $logfile - Specify what server, share, and file is needed ; $logdata - Data to be written to the log ; ;Remarks This script addresses an issue with writing to logs if the file is open by ; another user it waits until they are done and has the log file closed. ; It does a 1 second wait until ready to write to the log till a maximum of 6 seconds and then exits the routine. ; The 5x3 wait routine is not used anymore. ; ;Returns Writes to a file. No visible user output. ; ;Dependencies All Domain Users being able to write to a server share ; ;KiXtart Ver 4.02 ; ;Example(s) ; -- Data ; $logshare='\\SERVER\LOGINFO' ; $logfile=$logshare+'\HOTBAR.TXT' ; $logdata=@date + ',' + @time + ',' + @userid + ',WinNT,' + @wksta + @CRLF ; ; -- Example ; LOGGER($logfile,$logdata) ; FUNCTION LOGGER($logfile,$logdata) DIM $n WHILE Open(1,$logfile,5)<>0 IF $n '.' ELSE ? 'Please wait' ENDIF $n=$n+1 IF $n=6 EXIT(1) ENDIF SLEEP 1 LOOP $n=WriteLine(1, $logdata) $n=Close(1) ENDFUNCTION
;FUNCTION WMIQuery ;ACTION Queries WMI information from supported systems ;AUTHOR Radimus ;CONTRIBUTORS kdyer, Shawn, And Howard ;VERSION 2.4 ;DATE CREATED 12/22/2001 ;DATE MODIFIED 09/23/2003 ;KIXTART 4.x ;SYNTAX WMIQuery($what,$from,optional $computer,optional $where, optional $x) ; ;PARAMETERS $what ; ; ; $from ; Win32 Collection ; ; optional $computer ; defaults to local PC ; ; optional $where ; addl parameter for a 'WHERE' clause. Used with $x ; ; optional $x ; addl parameter for a 'WHERE' clause. Used with $Where ; ; ;RETURNS Array ; @error 1 = Cannot create COM object on target PC ; ;REMARKS This is chage alters the return from the function into an ARRAY, where the previous version ; was a pipe '|' delimited string. If you are updating to this version, check your code closely ; ;DEPENDENCIES kix 4.x+, WMI ; ;EXAMPLE $make = WMIQuery("Manufacturer","Win32_ComputerSystem")[0] ; $modem = WMIQuery("Description","Win32_POTSModem",$remotePC,"Status","OK")[0] ; for each $stick in WMIQuery("Capacity","Win32_PhysicalMemory") ; ? val($stick) / 1048576 ; next ; ;KIXTART BBS http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000117 ; http://download.microsoft.com/download/platformsdk/wmicore/1.5/W9XNT4/EN-US/wmicore.EXE
FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root) Dim $sQuery, $objEnum, $sValue, $sItem, $TMP, $SystemSet, $, $objInstance If Not $sComputer $sComputer="." EndIf if instr($sComputer,'\') $sComputer=right($sComputer,instrrev($sComputer,'\')) Endif if not $root $root="\root\cimv2" Endif $sQuery = "Select " + $sWhat + " From "+ $sFrom If $sWhere AND $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf $SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root) If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf $objEnum = $SystemSet.ExecQuery($sQuery) If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf For Each $objInstance in $objEnum If $objInstance $=Execute("$"+"sValue = $"+"objInstance."+$sWhat) if VarType($sValue) & 8192 For Each $sItem in $sValue $tmp=$tmp+'|'+Trim($sItem) Next else $tmp=$tmp+'|'+Trim($svalue) Endif EndIf Next $WMIQuery = split(substr($tmp,2),'|') Exit VAL("&"+Right(DecToHex(@ERROR),4)) ENDFUNCTION
Thanks!
Kent
|
Top
|
|
|
|
#125283 - 2004-08-18 08:38 PM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok.. Boiling this down, I have tried.. Code:
$b=$oXL.cells($Row,1).value $ip=WSHPing($b)[0] $u=WMIQuery("username","Win32_ComputerSystem",$b)[0] ?$b ?$ip ?$u
also have tried - Code:
$b=$oXL.cells($Row,1).value $ip=WSHPing("$b")[0] $u=WMIQuery("username","Win32_ComputerSystem","$b")[0] ?$b ?$ip ?$u
And.. Code:
$b=$oXL.cells($Row,1).value $ip=WSHPing('"'+$b+'"')[0] $u=WMIQuery("username","Win32_ComputerSystem",'"'+$b+'"')[0] ?$b ?$ip ?$u
Tried this with - Code:
$b=$ip=WSHPing($oXL.cells($Row,1).value)[0] $u=WMIQuery("username","Win32_ComputerSystem",$oXL.cells($Row,1).value)[0] ?$oXL.cells($Row,1).value ?$ip ?$u
Thanks,
Kent
|
Top
|
|
|
|
#125285 - 2004-08-18 09:20 PM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I am getting a message -
Quote:
ERROR : unexpected command! Script: C:\!Kix\ip.KIX Line : 23
Line 23 shows us - Code:
$u=WMIQuery("username","Win32_ComputerSystem",$b)[0]
Thanks!
Kent
|
Top
|
|
|
|
#125288 - 2004-08-19 01:15 AM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
OK..
Quote:
error reported:1722
Interesting that it shows -
Quote:
C:\Documents and Settings\kdyer>net helpmsg 1722
The RPC server is unavailable.
Now, that I think about this.. I am running XP SP-2. I have turned off the Firewalll and other stuff.. Hmm..
Thanks,
Kent
|
Top
|
|
|
|
#125289 - 2004-08-19 05:38 AM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Don't know if that is the whole story. Tried to run this under XP Sp-1, but still see the same the same thing.
Kent
|
Top
|
|
|
|
#125291 - 2004-08-19 05:59 AM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Doc,
Been kinda slammed at work. Anyway, we be chattin' now.
Kent
|
Top
|
|
|
|
#125293 - 2004-08-19 02:13 PM
Re: Having problems with Vars
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
I don't know kent. With the changes i made to WshPing, the following seems to work just fine for me. (Windows XP SP1, kix ver 4.22)
Code:
cls break on DIM $oxl,$Row,$b,$ip,$make,$model,$sn,$cs,$mm,$mt,$,$u $rc=SETOPTION('Explicit','On') $rc=SETOPTION('NoVarsInStrings','On')
$oXL=Createobject('Excel.application') ;Check to insure that Excel is available IF 0<>@error ?@error ' Excel Application is not found' SLEEP 4 RETURN ENDIF $Rc=$oXL.workbooks.open('c:\ie6push.xls') $Row=1 ;Row to start at using column headings, change to 0, if needed WHILE $oXL.cells($Row,1).value<>'' ;need a value each time in column 1 $Row=$Row+1 IF $oXL.cells($Row,1).value='' ;Once it gets to a blank row... $oXL.quit ;quit Excel $oXL=0 ;set the object to 0 ELSE $b=$oXL.cells($Row,1) $ip=WSHPing($b)[0] $u=WMIQuery("username","Win32_ComputerSystem",$b)[0] $make = WMIQuery("Manufacturer","Win32_ComputerSystem",$b)[0] $model=WMIQuery("Model","Win32_ComputerSystem",$b)[0] $sn=WMIQuery("SerialNumber","Win32_BIOS",$b)[0] $cs=WMIQuery("CurrentClockSpeed","Win32_Processor",$b)[0] $mm=WMIQuery("MonitorManufacturer","Win32_DesktopMonitor",$b)[0] $mt=WMIQuery("MonitorType","Win32_DesktopMonitor",$b)[0] ?$b ?$ip ?$u ?$make ? $model ? $sn ? $cs ? $mm ? $mt ENDIF LOOP ?'process is complete' get $
_________________________
Eric
|
Top
|
|
|
|
#125297 - 2004-08-20 02:30 PM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
It still is giving me a hard time. Tried to use the GLOBAL and it does not want to play either.
Kent
|
Top
|
|
|
|
#125299 - 2004-08-20 06:52 PM
Re: Having problems with Vars
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Using your latest version of the code.. Gives me -
Quote:
ERROR : unexpected command! Script: C:\!Kix\ip.KIX Line : 24
Line 24 is - Code:
$u=WMIQuery("username","Win32_ComputerSystem",$b)[0]
thanks!
Kent
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 557 anonymous users online.
|
|
|