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