Page 1 of 2 12>
Topic Options
#125281 - 2004-08-18 07:51 PM Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125282 - 2004-08-18 07:59 PM Re: Having problems with Vars
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
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.
_________________________
Eric

Top
#125283 - 2004-08-18 08:38 PM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125284 - 2004-08-18 08:53 PM Re: Having problems with Vars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22302
Loc: OK
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?
_________________________
!

download KiXnet

Top
#125285 - 2004-08-18 09:20 PM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125286 - 2004-08-18 09:37 PM Re: Having problems with Vars
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
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.
_________________________
Eric

Top
#125287 - 2004-08-18 09:38 PM Re: Having problems with Vars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22302
Loc: OK
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?
_________________________
!

download KiXnet

Top
#125288 - 2004-08-19 01:15 AM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125289 - 2004-08-19 05:38 AM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125290 - 2004-08-19 05:47 AM Re: Having problems with Vars
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11558
Loc: CA
Kent

You disable PM ?

Don't ever see you on AOL/MSN either

Top
#125291 - 2004-08-19 05:59 AM Re: Having problems with Vars
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc,

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

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125292 - 2004-08-19 08:31 AM Re: Having problems with Vars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22302
Loc: OK
hey, echo the $b before:
$u=WMIQuery("username","Win32_ComputerSystem",$b)

it kinda sounds like $b is invalid...
_________________________
!

download KiXnet

Top
#125293 - 2004-08-19 02:13 PM Re: Having problems with Vars
maciep Offline
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
#125294 - 2004-08-19 04:45 PM Re: Having problems with Vars
Happy Birthday Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Are you blocking ICMP traffic at all? If I be remembering correctly doesn't RPC rely on ICMP?
Top
#125295 - 2004-08-19 09:37 PM Re: Having problems with Vars
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
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.



_________________________
Eric

Top
#125296 - 2004-08-19 09:42 PM Re: Having problems with Vars
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22302
Loc: OK
lol!
_________________________
!

download KiXnet

Top
#125297 - 2004-08-20 02:30 PM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125298 - 2004-08-20 02:33 PM Re: Having problems with Vars
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I don't see what making your vars global would accomplish. Are you still getting the same error (1722)? What code are using now?
_________________________
Eric

Top
#125299 - 2004-08-20 06:52 PM Re: Having problems with Vars
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#125300 - 2004-08-20 07:02 PM Re: Having problems with Vars
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
have you made any changes to the udfs?
_________________________
Eric

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 189 anonymous users online.
Newest Members
Steff, phanhuyen, Jeroen_Ruijter, Tienn, tmvngocdung42
17545 Registered Users

Generated in 0.124 seconds in which 0.06 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org