Kdyer
(KiX Supporter)
2004-08-18 07:51 PM
Having problems with Vars

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


maciep
(Korg Regular)
2004-08-18 07:59 PM
Re: Having problems with Vars

I don't do anything with excel, but i did notice in your script that you check

$oXL.cells($Row,1).value = ''

but you assign $b (which i'm assuming is the computer name) without the value property

$b=$oXL.cells($Row,1)

I'm not sure if that's a problem or not.


Kdyer
(KiX Supporter)
2004-08-18 08:38 PM
Re: Having problems with Vars

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


LonkeroAdministrator
(KiX Master Guru)
2004-08-18 08:53 PM
Re: Having problems with Vars

sorry kent, I must ask you to say what your problem is.
don't say that the script won't work as expected, we know that.
but what is going on?
what should we look at?


Kdyer
(KiX Supporter)
2004-08-18 09:20 PM
Re: Having problems with Vars

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


maciep
(Korg Regular)
2004-08-18 09:37 PM
Re: Having problems with Vars

also, you have novarsinstrings set, so you probably want to change you $shell var in WSHPing to

$shell='%comspec% /c %windir%\system32\ping ' + $Computer + ' -n ' + $replies

Right now WshPipe is trying to ping $Computer (literally) and same with $replies. I made that change and the ping portion of the script started working.


LonkeroAdministrator
(KiX Master Guru)
2004-08-18 09:38 PM
Re: Having problems with Vars

so, try instead of that line, this:
Code:

$u=WMIQuery("username","Win32_ComputerSystem",$b)
if @error
"error reported:" @error
get $ quit
endif
if not 0<=ubound($u)
"not array output on $u: ubound=" ubound($u)
get $ quit
endif
$u=$u[0]



simple tracing can save hours, right?


Kdyer
(KiX Supporter)
2004-08-19 01:15 AM
Re: Having problems with Vars

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


Kdyer
(KiX Supporter)
2004-08-19 05:38 AM
Re: Having problems with Vars

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


NTDOCAdministrator
(KiX Master)
2004-08-19 05:47 AM
Re: Having problems with Vars

Kent

You disable PM ?

Don't ever see you on AOL/MSN either


Kdyer
(KiX Supporter)
2004-08-19 05:59 AM
Re: Having problems with Vars

Doc,

Been kinda slammed at work. Anyway, we be chattin' now.

Kent


LonkeroAdministrator
(KiX Master Guru)
2004-08-19 08:31 AM
Re: Having problems with Vars

hey, echo the $b before:
$u=WMIQuery("username","Win32_ComputerSystem",$b)

it kinda sounds like $b is invalid...


maciep
(Korg Regular)
2004-08-19 02:13 PM
Re: Having problems with Vars

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 $




Chris S.
(MM club member)
2004-08-19 04:45 PM
Re: Having problems with Vars

Are you blocking ICMP traffic at all? If I be remembering correctly doesn't RPC rely on ICMP?

maciep
(Korg Regular)
2004-08-19 09:37 PM
Re: Having problems with Vars

if he is still using '$b' instead of $b in his parameters and novarsinstrings is on, then he's going to get error 1722.

From my eventlog

Quote:


DCOM was unable to communicate with the computer $b using any of the configured protocols.





LonkeroAdministrator
(KiX Master Guru)
2004-08-19 09:42 PM
Re: Having problems with Vars

lol!

Kdyer
(KiX Supporter)
2004-08-20 02:30 PM
Re: Having problems with Vars

It still is giving me a hard time. Tried to use the GLOBAL and it does not want to play either.

Kent


maciep
(Korg Regular)
2004-08-20 02:33 PM
Re: Having problems with Vars

I don't see what making your vars global would accomplish. Are you still getting the same error (1722)? What code are using now?

Kdyer
(KiX Supporter)
2004-08-20 06:52 PM
Re: Having problems with Vars

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


maciep
(Korg Regular)
2004-08-20 07:02 PM
Re: Having problems with Vars

have you made any changes to the udfs?

Kdyer
(KiX Supporter)
2004-08-20 07:49 PM
Re: Having problems with Vars

No changes to the udfs..

Other than the recommendation to change the PING Line, which seems to help.

Kent


LonkeroAdministrator
(KiX Master Guru)
2004-08-20 08:15 PM
Re: Having problems with Vars

obviously macieps last code does produce that error as it has no UDF included.
thus "unexpected command"
there is no such keyword in his last code.


maciep
(Korg Regular)
2004-08-20 08:50 PM
Re: Having problems with Vars

Jooel, i think it's safe to assume at this point that we all realize the udfs need to be there. i just didn't see any reason to repost them.

Kdyer
(KiX Supporter)
2004-08-20 09:08 PM
Re: Having problems with Vars

He's just trying to increase his post count!!

Kent


Chris S.
(MM club member)
2004-08-20 09:25 PM
Re: Having problems with Vars

Well, if we're looking at increasing our post count...

I notice that you're using an older version of WSHPipe, not that it should make any difference.


LonkeroAdministrator
(KiX Master Guru)
2004-08-20 10:05 PM
Re: Having problems with Vars

no, the error reported has a meaning.
and surely there is some silly reason for it, right kent?


Kdyer
(KiX Supporter)
2004-08-21 01:09 AM
Re: Having problems with Vars

Sure the RDP Message seems to be the root of this. However, when I explicitly define a computer, it works fine.. But when I read in the list from Excel, AD, etc. is where this chokes.

Kent


LonkeroAdministrator
(KiX Master Guru)
2004-08-21 01:22 AM
Re: Having problems with Vars

have you tried the script without setoptions?

Kdyer
(KiX Supporter)
2004-08-21 01:32 AM
Re: Having problems with Vars

Same error.. Same thing..

Kent


Kdyer
(KiX Supporter)
2004-08-21 01:41 AM
Re: Having problems with Vars

I feel pretty stupid now.

Here is the corrected code.. You need to insure the computer is awake and ready, right?

Note: the $ip[1] check.
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)
IF $ip[1]>0
$u=WMIQuery("username","Win32_ComputerSystem",$b)
$make=WMIQuery("Manufacturer","Win32_ComputerSystem",$b)
$model=WMIQuery("Model","Win32_ComputerSystem",$b)
$sn=WMIQuery("SerialNumber","Win32_BIOS",$b)
$cs=WMIQuery("CurrentClockSpeed","Win32_Processor",$b)
$mm=WMIQuery("MonitorManufacturer","Win32_DesktopMonitor",$b)
$mt=WMIQuery("MonitorType","Win32_DesktopMonitor",$b)
?$b
?$ip[0]
?$u[0]
?$make[0]
?$model[0]
?$sn[0]
?$cs[0]
?$mm[0]
?$mt[0]
ENDIF
ENDIF
LOOP
?'process is complete'
get $



Kent


Kdyer
(KiX Supporter)
2004-08-23 05:21 PM
Re: Having problems with Vars

Is there any way to detect if the is a machine off-line with this?

Kent


Kdyer
(KiX Supporter)
2004-08-24 06:16 PM
Re: Having problems with Vars

Here is what I have been able to put together on this:
Code:

CLS
BREAK ON

;DIM $oxl,$Row,$b,$ip,$make,$model,$sn,$cs,$mm,$mt,$,$u
;$rc=SETOPTION('Explicit','On')
;$rc=SETOPTION('NoVarsInStrings','On')
$fl='H:\mmc.csv'
IF exist($fl)
DEL $fl
ENDIF

$logdata='ComputerName,IP,User,Make,Model,Serial,Processor,Monitor,MonitorType'
LOGGER($fl,$logdata+@crlf)
$containername = @DOMAIN
$container = GetObject("WinNT://"+$containername)
$container.filter = "Computer", ""
FOR EACH $computer IN $container
$cn=$computer.name
IF LEFT($cn,4)='MMC0' AND LEN($cn)=8
IF RIGHT($cn,4)>=1300
$ip=WSHPing($cn)
?'checking '+$cn
SELECT CASE $ip[1]<0
$logdata=$cn+','$ip[0]
CASE NOT EXIST('\\'+$cn+'\admin$$')
$logdata=$cn+','$ip[0]
CASE EXIST('\\'+$cn+'\admin$$')
$u=WMIQuery("username","Win32_ComputerSystem",$cn)
$make=WMIQuery("Manufacturer","Win32_ComputerSystem",$cn)
$model=WMIQuery("Model","Win32_ComputerSystem",$cn)
$sn=WMIQuery("SerialNumber","Win32_BIOS",$cn)
$cs=WMIQuery("CurrentClockSpeed","Win32_Processor",$cn)
$mm=WMIQuery("MonitorManufacturer","Win32_DesktopMonitor",$cn)
$mt=WMIQuery("MonitorType","Win32_DesktopMonitor",$cn)
;?$cn
;?$ip[0]
;?$ip[1]
;?$u[0]
;?$make[0]
;?$model[0]
;?$sn[0]
;?$cs[0]
;?$mm[0]
;?$mt[0]
;ENDIF
$logdata=$cn+','+$ip[0]+','+$u[0]+','+$make[0]+','+$model[0]+','+$sn[0]+','+$cs[0]+','+$mm[0]+','+$mt[0]
ENDSELECT
LOGGER($fl,$logdata+@crlf)
ENDIF
ENDIF
NEXT
?'process is complete'
GET $



Requires:
WSHPING()
WSHPIPE()
LOGGER()
WMIQUERY()

Thanks!

Kent