#196285 - 2009-10-07 12:58 PM
Re: Tokenized scripts identification
[Re: BoForce]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
|
Here's a short version of the test script, after narrowing down the problem to be references to objects.;; KixGenerated: 2009/09/25 06:48:27
Break On
@Kix ?
ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\devices', 'Fax') ?
Test('farkle')
Ping('127.0.0.1')
Function Test($Arg)
'Arg is ' $Arg ?
EndFunction
;;
;;======================================================================
;;
;;FUNCTION ping()
;;
;;ACTION ping - Pings a host
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 2.0 - 2007/10/20 - WHS version
;; 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to
;; return values and IP's
;;
;;SYNTAX ping(host, [Flag], [Wait])
;;
;;PARAMETERS host - name of host to ping
;; FLAG - if negative, returns IP Address
;; if >0, specifies number of tries (default is 1)
;; Wait - optional ping timeout value
;;
;;
;;REMARKS ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS FLAG >= 0: returns 1 if host is reachable, 0 if not
;; FLAG < 0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES OS Commands Ping & Find
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES Ping('hostname') ; returns Success/Failure
;; Ping('hostname',-1) ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
'w'
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
'x'
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
'y'
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
'z'
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction Note that the Ping function is modified to display "wxyz" to monitor progress through the function. Tokenizing with 4.53 works with 4.60 but not 4.61. Tokenizing with 4.61 works with 4.61 but not with earlier releases. In either case, the error returned is G0PW01 - K:\KixBinaries>kix324.53 t.kx
4.53
winspool,Ne01:
Arg is farkle
wx
ERROR : IDispatch pointers not allowed in expressions!
Script: K:\KixBinaries\t.kix
Line : 90 From the fact that it displays "wx", you can see that the $oExec COM instantiation does not fail, but apparently does not return a proper value any longer, failing on the If Not VarType($_oExec)=9 line.
My login script displays an "invalid method/function call: too many parameters! yet references a block of comments as the offending line. Still haven't got to the bottom of that, yet, but have almost 3000 lines to work through.
Ruud says he didn't make any changes in the tokenizing components, so this is unexpected behavior, even though tokenizing isn't technically supported across Kix versions.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#196286 - 2009-10-07 01:06 PM
Re: Tokenized scripts identification
[Re: Richard H.]
|
BoForce
Fresh Scripter

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
|
The error is that it is missing a ')' in line:
$cloLoggingOrderColl = Split(ReadValue($_ini,"Logging Options","Logging Order"),';')
I never documented the version used for tokenized scripts as I've started using this from version 4.53 and have been using 4.53 since three years now. When I found out that it can fail, I adjusted my documentation regarding tokenizing kix script within our company. Besides documenting it, I've also added 4.61 to the Keywords within the properties of a .kx file.
Adding the version of Kix32 into the name of the script is a good suggestion.
|
Top
|
|
|
|
#196287 - 2009-10-07 01:28 PM
Re: Tokenized scripts identification
[Re: Glenn Barnas]
|
BoForce
Fresh Scripter

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
|
Thanks for explaining it to me.
I ran a bunch of tests after my login script failed, and it seems that just about every kix function will work, but include WshPipe(), or ADSIUserInfo() and it will die. I can confirm that I use WSHPipe() within the script.
Ruud says he didn't make any changes in the tokenizing components, so this is unexpected behavior, even though tokenizing isn't technically supported across Kix versions.
I have learned my lesson from this issue and will be more carefull in the future. The reason I started this post is to find out if anything would be possible to prevent this from happening again. As I replied earlier I've adjusted the documentation for scripting within our company and have taken several other actions, but that doesn't make it fail proof.
My login script displays an "invalid method/function call: too many parameters! yet references a block of comments as the offending line. Still haven't got to the bottom of that, yet, but have almost 3000 lines to work through. I know. My login script has 6704 lines and if Kix is missing something (in my case a ')' at line 4514) it doesn't mean that the typo is near 4514, but it could also be 50 or 100 lines before. Where to start.
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 707 anonymous users online.
|
|
|