Page 1 of 2 12>
Topic Options
#122840 - 2004-07-14 07:17 AM array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
I have compiled (errr, not compiled as in a compiler) a script and having some problems. If I map a network drive and call the file from the mapped drive during the logon process, no error occurs. However, from the logonscript, if I call usbData.kix, it errors our with Array out of bounds and I can't figure out why.

The error is said to be in line 33, which is the following section:
Code:
 

if $lines = -1
redim preserve $all[ubound($all)-1]
$tail = $all
exit(0)
endif



Here is the bulk of the file:
Code:
 

; ##########################
; Features
; - Check for USBSTOR.SYS for permissions
; - Check for active USB Controllers

break on
$file='c:\@wksta.ini'
$tmpFile='c:\tmpFile.txt'
$targetDrive='P:\COMSEC\dataCollection'
$targetFile='$targetDrive\USBresults.ini'
$failedFile='$targetDrive\USBfailed.txt'
;$targetFile='c:\USBresults.ini'
;$failedFile='c:\USBfailed.txt'
$RC=Open(1,$File)
$rdLine=ReadLine(7)
$perms1='No Access'
$perms2='-------'

? 'starting usbData.kix'

;################################################
;## Function to Tail the file (unix style)
Function Tail($file,optional $lines, optional $skip)
dim $fso,$f,$fs,$i,$all
if not $lines $lines = 1 endif
if not $skip $skip = 0 endif
$fso = CreateObject("Scripting.FileSystemObject")
$f = $fso.GetFile($file)
if @error exit(2) endif
$fs = $f.OpenAsTextStream(1)
if $skip $fs.Skip($skip) endif
$all = split($fs.Read($f.size-$skip),@crlf)
if $lines = -1
redim preserve $all[ubound($all)-1]
$tail = $all
exit(0)
endif
dim $out[$lines]
for $i = ubound($all)-$lines to ubound($all)
$out[$i-(ubound($all)-$lines)] = $all[$i]
next
redim preserve $out[ubound($out)-1]
$tail=$out Exit(0)
EndFunction

;################################################
;## Function to read the data in the file
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=chr(10)
$f=freefilehandle
$_=open($f,$file)
if @error exit @error endif
do $t=$t+$lf+readline($f) until @error
$_=close($f)
$ReadFile=split(substr($t,2),$lf)
EndFunction

;################################################
;## Function to merge datafiles to the server
Function MergeIni($SourceIni,$TargetIni,$Log)
Dim $Section,$AllSections
Dim $Key,$AllKeys,$Value,$_
; Check if SourceIni exists..
If Exist($SourceIni)=1
; Read all sections from Source ini file into AllSections array..
$AllSections=Split(ReadProfileString($SourceIni,"",""),Chr(10))
; Read section subkeys..
For Each $Section In $AllSections
; Section not empty..
If $Section<>""
; Local parameters..
$AllKeys=Split(ReadProfileString($SourceIni,$Section,""),Chr(10))
; Read section subkeys..
For Each $Key In $AllKeys
; Key not empty..
If $Key<>""
$Value=ReadProfileString($SourceIni,$Section,$Key)
$_=WriteProfileString($TargetIni,$Section,$Key,$Value)
If $Log<>""
Shell "%ComSpec% /c echo - write $Key=$Value in [$Section]>>$Log"
EndIf
EndIf
Next
EndIf
Next
; Merge succesfull..
Exit(1)
Else
; Source INI file error..
Exit(0)
EndIf
EndFunction

;################################################
; START THE SCRIPT

; Open file and set header
$nul = open(1, $file, 5)
$nul = writeline(1, "[@wksta]" + @crlf)
$nul = close(1)

; Get the permissions for the USBSTOR.SYS file and strip it for the datafile
SHELL "CMD.EXE /C perms /i users c:\winnt\system32\drivers\usbstor.sys > $tmpFile"
for each $line in tail($tmpFile,-1,42)
$aPerms=Split($line,':')
$sPerms=$aPerms[1]
$sPerms=trim("$sPerms")
if $sPerms <> $perms1
writeprofilestring($file,@wksta,'users',$sPerms)
else
if $sPerms <> $perms2
writeprofilestring($file,@wksta,'users',$sPerms)
endif
endif
next
del $tmpFile


SHELL "CMD.EXE /C perms /i @userid c:\winnt\system32\drivers\usbstor.sys > $tmpFile"
for each $line in tail($tmpFile,-1,42)
$bPerms=Split($line,':')
$tPerms=$bPerms[1]
$tPerms=trim("$tPerms")
if $tPerms <> $perms1
writeprofilestring($file,@wksta,@userid,$tPerms)
else
if $tPerms <> $perms2
writeprofilestring($file,@wksta,@userid,$tPerms)
endif
endif
next
del $tmpFile


SHELL "CMD.EXE /C perms /i administrators c:\winnt\system32\drivers\usbstor.sys > $tmpFile"
for each $line in tail($tmpFile,-1,42)
$cPerms=Split($line,':')
$uPerms=$cPerms[1]
$uPerms=trim("$uPerms")
if $uPerms <> $perms1
writeprofilestring($file,@wksta,'administrators',$uPerms)
else
if $uPerms <> $perms2
writeprofilestring($file,@wksta,'administrators',$uPerms)
endif
endif
next
del $tmpFile

; Look for the USB device and list it if it is ACTIVE
Dim $SO,$strComputer,$objWMIService,$colItems,$objItem
$i = 1
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_USBController",,48)
For Each $objItem in $colItems
if $objItem.ConfigManagerErrorCode = "0"
$nul = open(1, $file, 5)
$nul = writeline(1, "UsbController" + $i + "=" + $objItem.Description + @crlf)
$nul = close(1)
$i = $i + 1
else
$nul = writeprofilestring($file,@wksta,'UsbController','NOT AVAILABLE')
endif
Next

; Force a line feed at end of file
$nul = open(1, $file, 5)
$nul = writeline(1, @crlf)
$nul = close(1)

; Merge the files
Dim $MergeFile
$MergeFile = MergeIni($file,$targetFile,'')
If $MergeFile <> 0
$nul = open(8, $failedFile, 5)
$nul = writeline(8, @wksta + @crlf)
$nul = close(8)
else
? 'File Merge Successful'
Endif

; Force a line feed at end of targetFile
$nul = open(9, $targetFile, 5)
$nul = writeline(9, @crlf)
$nul = close(9)

; Delete the file from the local workstation
del $file



Edited by jechilt (2004-07-14 05:11 PM)
_________________________
John
LM Contractor
One of the 2 dads

Top
#122841 - 2004-07-14 07:53 AM Re: array out of bounds...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well...
if all is 1 element array ($all[0]) doing:
redim preserve $all[ubound($all)-1]

would make:
dim $all[-1]
_________________________
!

download KiXnet

Top
#122842 - 2004-07-14 08:26 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
hmmm,
i am not too smart when it comes to arrays (yeah, I use the examples in the forum)...
i am looking at this and trying to figure out exactly what you are saying.
I tried changing the dim as you suggested and it still gives array reference out of bounds.
any suggestions?
_________________________
John
LM Contractor
One of the 2 dads

Top
#122843 - 2004-07-14 08:34 AM Re: array out of bounds...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
didn't really suggest anything.
I said the reason why it most likely is crashing.
there is no such array that has ubound of -1.

so, to test that situation, place simple:
ubound($all) ?

before your redim line.
if it gives 0, you can't reduce the ubound, obviously.
_________________________
!

download KiXnet

Top
#122844 - 2004-07-14 08:50 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
hmmm, ok. the ubound return is currently -1-

btw...on a personal note, i think my lack of knowledge amplifies the intimidation set by your photo shot

thanks for the help so far...and since i am lost in this..can you continue to assist?
_________________________
John
LM Contractor
One of the 2 dads

Top
#122845 - 2004-07-14 09:01 AM Re: array out of bounds...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the return can't be:
-1-

obviously.
is it 1 or -1 or?
_________________________
!

download KiXnet

Top
#122846 - 2004-07-14 09:07 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
sorry about the format. the response is:

Code:
 1 

_________________________
John
LM Contractor
One of the 2 dads

Top
#122847 - 2004-07-14 09:24 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
could it be this easy?

changed:
Code:
 dim $fso,$f,$fs,$i,$all 



to:
Code:
 dim $fso,$f,$fs,$i,$all[100] 



No more "array reference out of bounds" message...
_________________________
John
LM Contractor
One of the 2 dads

Top
#122848 - 2004-07-14 09:48 AM Re: array out of bounds...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you could try also:
dim $all[0] instead of 100.

little explaining.
you dimmed (initialized) the var as normal variable.
with [anything] you initialize it as array.

if you don't feed it with array, it will never be array and that surely does cause errors.
also, with right after the dim line you could have done:
$all=0,0
or:
$all="",""

to do same but little longer.
the real deal is to find out why it never gets to array state.
should $all have some info in it? as it seems it never gets any.
_________________________
!

download KiXnet

Top
#122849 - 2004-07-14 11:12 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
ok....thanks!
will keep this in mind
_________________________
John
LM Contractor
One of the 2 dads

Top
#122850 - 2004-07-14 02:54 PM Re: array out of bounds...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

I have compiled a script and having some problems. If I map a network drive and call the file from the mapped drive during the logon process, no error occurs. However, from the logonscript, if I call usbData.kix, it errors our with Array out of bounds and I can't figure out why.

The error is said to be in line 33, which is the following section:
Code:
 
if $lines = -1
redim preserve $all[ubound($all)-1]
$tail = $all
exit(0)
endif








jechilt,

you can remove
Code:

redim preserve $all[ubound($all)-1]



from the tail udf. Sorry about that bug . I have no idea why i was wanting to redim the array there.....

Top
#122851 - 2004-07-14 03:50 PM Re: array out of bounds...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

I have compiled a script



That would be quite a feat since there is no such thing as a KiX compiler!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122852 - 2004-07-14 04:19 PM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
Sorry for the confusion....i was referring to the webster definition of 'compile', as in number 1 and 2, not 3.
<snip>
1 : to compose out of materials from other documents
2 : to collect and edit into a volume
3 : to run (as a program) through a compiler
4 : to build up gradually <compiled a record of four wins and two losses>
<end snip>

I will do my best to be more aware of the words used in the threads...
_________________________
John
LM Contractor
One of the 2 dads

Top
#122853 - 2004-07-14 04:55 PM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
ok...this script is kicking my 'tail'!!!

i admit it...i don't understand arrays. if i did, this would probably be easy to solve. can you please help me???

got the function array out of bounds error resolved. however, now another piece is out of bounds and for the life of me, i don't know why...it used to work and now it doesnt.

function code:
Code:
 
;################################################
;## Function to Tail the file (unix style)
Function Tail($file,optional $lines, optional $skip)
dim $fso,$f,$fs,$i,$all
if not $lines $lines = 1 endif
if not $skip $skip = 0 endif
$fso = CreateObject("Scripting.FileSystemObject")
$f = $fso.GetFile($file)
if @error exit(2) endif
$fs = $f.OpenAsTextStream(1)
if $skip $fs.Skip($skip) endif
$all = split($fs.Read($f.size-$skip),@crlf)
if $lines = -1
; DONT NEED redim preserve $all[ubound($all)-1]
$tail = $all
exit(0)
endif
dim $out[$lines]
for $i = ubound($all)-$lines to ubound($all)
$out[$i-(ubound($all)-$lines)] = $all[$i]
next
redim preserve $out[ubound($out)-1]
$tail=$out Exit(0)
EndFunction



the portion of the script that is calling the function
Code:
 
for each $line in tail($tmpFile,-1,42)
$cPerms=Split($line,':')
$uPerms=$cPerms[1]
$uPerms=trim("$uPerms")
if $uPerms <> $perms1
writeprofilestring($file,@wksta,'administrators',$uPerms)
else
if $uPerms <> $perms2
writeprofilestring($file,@wksta,'administrators',$uPerms)
endif
endif
next



the script is causing an error, array reference out bounds
Code:
 $sPerms=$aPerms[1]



what I don't understand is this 'was' working and then, it seems like all of a sudden it does not want to work anymore....and i am lost.

your expertise is appreciated
_________________________
John
LM Contractor
One of the 2 dads

Top
#122854 - 2004-07-14 05:25 PM Re: array out of bounds...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Maybe a blank $line in the file.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122855 - 2004-07-14 05:37 PM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
yes....there is a blank line on the first line. the data is output to the second line.
when i run the debug, it runs through the first time and get the information, but then the second loop through, it fails with the array reference out of bounds error
_________________________
John
LM Contractor
One of the 2 dads

Top
#122856 - 2004-07-14 06:03 PM Re: array out of bounds...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Not having the original file to test with, I can only go by what you say. In your FOR loop, you go through each element in the array which you then Split() into yet another array on a full colon ':'. If the $line does not contain a colon, there is no $cPerms[1], hence 'out of bounds'.

Walk through in debug and query the vars to see what you are getting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122857 - 2004-07-14 06:37 PM Re: array out of bounds...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
when working with arrays with kix, it is always a good idea to check the ubound() of an array before you call an array index. If you check and see that the Ubound() is less then the index you are about to call, you can then program a workaround so that a error does not happen...


also... some helpful array programming hints...

Code:

;the ubound($string) equals 3
;calling string[4] will cause an error.
$string = "a:b:c:d"
$string = split($string,":")
$var = $string[4]



;but, this does not cause an error...
$string = "a:b:c:d"
$var = split($string,":")[4]





Edited by Bryce (2004-07-14 06:38 PM)

Top
#122858 - 2004-07-15 07:16 AM Re: array out of bounds...
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
thanks for the pointer.
if it helps, I can upload or make available all the files that this process is using.

one thing I find interesting is the script is not running fine as an administrator, but continue to get the array error when logging on as a regular user (no elevated rights). this is throwing me...like a rag doll.
_________________________
John
LM Contractor
One of the 2 dads

Top
#122859 - 2004-07-15 07:37 AM Re: array out of bounds...
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Bryce,

how come the second one doesn't crash???

I'm a bit confused...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.175 seconds in which 0.125 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