When I launch this script :

code:
 $Resource = "\\Server1\Site"
? $Resource + " : Processing ..."
Gosub ConnectResource

$Resource = "\\Server2\Site"
? $Resource + " : Processing ..."
Gosub ConnectResource

$Resource = "\\Server3\Site"
? $Resource + " : Processing ..."
Gosub ConnectResource

$Resource = "\\Server4\Site"
? $Resource + " : Processing ..."
Gosub ConnectResource

? "End Of Proc."
Return

:ConnectResource
$FileAndDirCount = 0

Use "V:" "$Resource"
If @Error = 0
$Dummy = Dir("V:\*.")
If @Error = 0
While @Error = 0
$FileAndDirCount = $FileAndDirCount + 1
$Dummy = Dir()
Loop
Else
? @ERROR
EndIf
Use "V:" /Del
Else
? "Use Cmd : " + @ERROR
EndIf
? "File(s) And Dir(s) : " + "$FileAndDirCount"

Return

Everything Looks AllRight.

So I managed to rewrite just a little to make this code more flexible with parameters files. That's perhaps a choice which could certainly be discussed, but ...

Here's the modified script :
code:
 
CLS

$BeginTicks = @TICKS
$BeginDate = @DATE
$BeginTime = @TIME
$ScriptName = Ucase(@ScriptName)

;***********************************************
; Initialize Varz For File Handle
;***********************************************
$ParmsFName = "_Connect-Parms.Kix"
$ExecLogFName = "_Connect-ExecLog.Log"
$ResourceNamesFName = "_Connect-ResourceNames.Kix"
$ParmsFHndle = 1
$ExecLogFHndle = 2
$ResourceNamesFHndle = 3
$Proc2Execute = ""

;Command Line Parms Prevail Over ParmsFile & Default
Select
Case $InfoMode = 0 AND $InfoMode <> ""
; Tricky BeHavior Of KiX With CmdLine Parms, Isn't it ?
; Nothing To Do, Msgs will Be Hidden
Case $InfoMode = 1
; Nothing To Do, Msgs Will Be Sent 2 Screen
Case $InfoMode = 2
Gosub InitExecLogFileJobs
Case $InfoMode = 3
Gosub InitExecLogFileJobs
Case $InfoMode = ""
Gosub Check4InfoMode
Case 1
Gosub Check4InfoMode
EndSelect

$Dummy = Info($ScriptName + " ! " + $BeginDate + " " + $BeginTime)
$Dummy = LDel("-")

;***********************************************
; Initialize Varz
;***********************************************
$Proc2Execute = ""
$DeviceName = ""
Gosub Check4UserDefParms

Gosub Check4AvailableDevice

Dim $ResourceNamesArray[500]
$ResourceNamesArrayIdx = 0
$ProcessedResourceNames = 0
$ResourceName = ""
Gosub CreateResourceNamesTable

Gosub Device2ResourceAffectation


$Dummy = LDel("-")

$EndDate = @DATE
$EndTime = @TIME
$EndTicks = @TICKS
$ResultScnds = ($EndTicks - $BeginTicks) / 1000

$DummyHrs = $ResultScnds / 3600
$Hrs = Int($DummyHrs)
$ScndsLessHrs= $ResultScnds - ($Hrs * 3600)
$DummyMnts = $ScndsLessHrs / 60
$Mnts = Int($DummyMnts)
$ScndsRemains= $ScndsLessHrs - ($Mnts * 60)
$Scnds = Fix($ScndsRemains)
$Dummy = Info("Approx. Time Elapsed : " + "$Hrs" + " H " + "$Mnts" + " ' " + "$Scnds" + ' "')

$Dummy = LDel("-")
$Dummy = Info($ScriptName + " ! " + $EndDate + " " + $EndTime)

If $InfoMode = 2 OR $InfoMode = 3
Gosub EndExecLogFileJobs
Else
EndIf

Return
; End Of Main Prog.

;****************************************************************************
; :Check4InfoMode
;****************************************************************************
; Looks For User's InfoMode Setting
;***********************************************
:Check4InfoMode
If Open($ParmsFHndle, $ParmsFName) = 0
$Line = ReadLine($ParmsFHndle)
While @Error = 0
$Line = Ucase(Ltrim(Rtrim($Line)))
If SubStr($Line,1,8) = "INFOMODE"
Select
Case $Line = "INFOMODE=0"
$InfoMode = 0
Case $Line = "INFOMODE=1"
$InfoMode = 1
Case $Line = "INFOMODE=2"
$InfoMode = 2
Gosub InitExecLogFileJobs
Case $Line = "INFOMODE=3"
$InfoMode = 3
Gosub InitExecLogFileJobs
Case 1
$InfoMode = 1
$Dummy = Info("Bad Data For InfoMode In " + $ParmsFName + ",")
$Dummy = Info("This Parameter Has Been Forced To 1 (Screen Only)")
$Dummy = Info("")
EndSelect
Else
EndIf
$Line = ReadLine($ParmsFHndle)
Loop
If Close($ParmsFHndle) = 0
Else
$ContextError = "Closing Parameters File : " + $ParmsFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf
Else
$ContextError = "Opening Parameters File : " + $ParmsFName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf

Return

;****************************************************************************
; :Check4UserDefParms
;****************************************************************************
:Check4UserDefParms
;***********************************************
; No More Looks For UserName (Operator) To Connect
; No More Looks For PWDUserName To Connect
; Looks For Resource To Assign
; Looks For Script To Execute
;***********************************************
If Open($ParmsFHndle, $ParmsFName) = 0
$Line = ReadLine($ParmsFHndle)
While @Error = 0
$TLine = Ucase(Ltrim(Rtrim($Line)))
Select
Case SubStr($TLine,1,10) = "DEVICENAME"
$DeviceName = Rtrim(Right($Line,Len($Line)-11))
Case SubStr($TLine,1,12) = "PROC2EXECUTE"
$Proc2Execute = Rtrim(Right($Line,Len($Line)-13))
Case 1
EndSelect
$Line = ReadLine($ParmsFHndle)
Loop
If Close($ParmsFHndle) = 0
Else
$ContextError = "Closing Parameters File : " + $ParmsFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf
Else
$ContextError = "Opening Parameters File : " + $ParmsFName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf

Return


;****************************************************************************
; :CreateResourceNamesTable
;****************************************************************************
:CreateResourceNamesTable

If Open($ResourceNamesFHndle,$ResourceNamesFName) = 0
$Dummy = Info("Opening File " + $ResourceNamesFName)
$RejectedLines = 0
$ResourceName = ReadLine($ResourceNamesFHndle)
While @Error = 0
If SubStr($ResourceName,1,2) = "\\"
$Dummy = Info("Adding : " + $ResourceName)
$ResourceNamesArray[$ResourceNamesArrayIdx] = $ResourceName
$ResourceNamesArrayIdx = $ResourceNamesArrayIdx + 1
Else
$RejectedLines = $RejectedLines + 1
EndIf
$ResourceName = ReadLine($ResourceNamesFHndle)
Loop
If Close($ResourceNamesFHndle) = 0
$Dummy = Info("Closing File " + $ResourceNamesFName)
Else
$ContextError = "Closing File : " + $ResourceNamesFName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf
Else
$ContextError = "Opening File : " + $ResourceNamesFName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf

; Report
$ProcessedResourceNamesNumber = $ResourceNamesArrayIdx
$Dummy = Info("Resource Name(s) Added : " + "$ProcessedResourceNamesNumber")
$Dummy = Info("Rejected Line(s) : " + "$RejectedLines" + " (Did'nt Begin With '\\')")
If $ProcessedResourceNamesNumber > 0
; UseLess Values Deletion
ReDim Preserve $ResourceNamesArray[$ProcessedResourceNamesNumber - 1]
Else
$ContextError = "Resource Name(s) To Manage : " + "$ProcessedResourceNamesNumber"
$NoError = "Internal Test"
$StringError = "No Resource Will Be Connected !"
$Fatal = 1
Gosub ErrorHandling
EndIf

Return


;****************************************************************************
; :Device2ResourceAffectation
;****************************************************************************
:Device2ResourceAffectation
For Each $ProcessedResourceName In $ResourceNamesArray
$Dummy = LDel("=")
$ResourceName = $ProcessedResourceName
$Dummy = Info("Connecting To " + $ResourceName + " ...")
Use "$DeviceName" "$ResourceName"
If @Error = 0
$Dummy = Info($DeviceName + " Connected To " + $ResourceName)
$Dummy = LDel("*")
$Dummy = Dir("$Proc2Execute")
If $Dummy <> "" AND @Error = 0
$Dummy = Info("Calling External Script : " + $Proc2Execute)
Call "$Proc2Execute"
$Dummy = Info("Returning from Ext. Script : " + $Proc2Execute)
Else
If $Dummy = ""
$Dummy = Info("Calling Internal Procedure : JobToDo")
Gosub JobToDo
$Dummy = Info("Returning From Internal Proc. : JobToDo")
Else
$ContextError = "Trying to find Script : " + $Proc2Execute + " Specified in " + $ParmsFName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf
EndIf
$Dummy = LDel("*")

$Dummy = Info("DisConnecting From " + $ResourceName + " ...")
Use "$DeviceName" /Del
If @Error = 0
$Dummy = Info($DeviceName + " Correctly DisConnected From " + $ResourceName)
Else
$ContextError = "DisConnection From " + $ResourceName + " For " + $DeviceName
$NoError = @Error
$StringError = @SError
$Fatal = 1
Gosub ErrorHandling
EndIf
Else
$ContextError = "Connection To " + $ResourceName + " For " + $DeviceName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf
Next

Return

;****************************************************************************
; :Check4AvailableDevice
;****************************************************************************
:Check4AvailableDevice
$PotentialDeviceNamesList = "Y:","X:","W:","V:","U:",
"T:","S:","R:","Q:","P:","O:",
"N:","M:","L:","K:","J:","I:",
"H:","G:","F:","E:","D:"
$PotentialDeviceNamesListIdx = 0
$PotentialDevice = ""

If $DeviceName = ""
; No DeviceName found in parameters file
$Dummy = Info("Scanning For One Potential Device ...")
$PotentialDevice = $PotentialDeviceNamesList[$PotentialDeviceNamesListIdx]
While $DeviceName = "" AND $PotentialDeviceNamesListIdx < 21
If Dir("$PotentialDevice" + "\*.*") = ""
$DeviceName = $PotentialDevice
Else
;$Dummy = Info("Device " + $PotentialDevice + " Is Already In Use")
$DeviceName = ""
EndIf
$PotentialDeviceNamesListIdx = $PotentialDeviceNamesListIdx + 1
$PotentialDevice = $PotentialDeviceNamesList[$PotentialDeviceNamesListIdx]
Loop
Else
; A Value For $DeviceName Has Been Set In ParmsFile
; Checks If Range (D To Y) and Syntax (Letter & Double Dot) are Correct
; This is Performed By Comparing With the values previously declared
; in Array $PotentialDeviceNamesList
$DummyTemp = Ucase($DeviceName)
$DeviceName = ""
For Each $PotentialDevice In $PotentialDeviceNamesList
If $DummyTemp = $PotentialDevice
$DeviceName = $DummyTemp
Else
EndIf
Next

If $DeviceName = ""
; This declared Device was not in the list of $PotentialDeviceNamesList
$ContextError = "Can't Connect The Device " + $DummyTemp + " To AnyThing !"
$NoError = "No Error Number"
$StringError = "No Error Text"
$Fatal = 1
Gosub ErrorHandling
Else
If Dir("$DeviceName" + "\*.*") = ""
; This declared Device was correctly declared And is'nt already in Use
Else
$ContextError = "Device " + $DeviceName + " Is Already In Use"
$NoError = "No Error Number"
$StringError = "No Error Text"
$Fatal = 0
Gosub ErrorHandling
$DeviceName = ""
EndIf
EndIf
EndIf

If $DeviceName = ""
; Declared DeviceName unavailable or no ScannedDeviceName Available
$ContextError = "Unable To Connect A Device"
$NoError = "No Error Number"
$StringError = "No Error Text"
$Fatal = 1
Gosub ErrorHandling
Else
$Dummy = Info("Using Device " + $DeviceName)
EndIf

Return

;****************************************************************************
; :ErrorHandling
;****************************************************************************
:ErrorHandling
;(Needs Actualized Values For $ContextError, $NoError, $StringError, $Fatal)

Beep
$Dummy = LDel("*")
$Dummy = Info("* FAILED : " + $ConTextError)
$Dummy = Info("* [" + $NoError + "] " + $StringError)
$Dummy = LDel("*")

If $Fatal = 1
Beep
$Dummy = LDel("*")
$Dummy = Info("* Aborting Script " + $ScriptName + " ...")
$Dummy = LDel("*")

Quit
Else

EndIf

Return

;****************************************************************************
; :InitExecLogFileJobs
;****************************************************************************
:InitExecLogFileJobs

If Exist($ExecLogFName)
Del $ExecLogFName
Else
EndIf
If Open($ExecLogFHndle, $ExecLogFName, 5) = 0
$Dummy = Info("Opening Log File : " + $ExecLogFName)
Else
$ContextError = "Opening Log File : " + $ExecLogFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
$InfoMode = 1
$Dummy = Info("Due to the preceding error, InfoMode is now forced To 1")
EndIf

Return

;****************************************************************************
; :EndExecLogFileJobs
;****************************************************************************
:EndExecLogFileJobs

$Dummy = Info("Closing Log File : " + $ExecLogFName)
If Close($ExecLogFHndle) = 0
Else
$ContextError = "Closing Log File : " + $ExecLogFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf

Return

;***********************************************
; Declare Functions For General Purpose
;***********************************************
Function Info($InfoText)

Select
Case $InfoMode = 0
; No Report At All
Case $InfoMode = 1
; Report To Screen Only
? $InfoText
Case $InfoMode = 2
; Report To Log File And Screen
? $InfoText
$Dummy = WriteLine($ExecLogFHndle, $InfoText + Chr(13) + Chr(10))
If $Dummy = 0
Else
$ContextError = "Writing in Log File : " + $ExecLogFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf
Case $InfoMode = 3
; Report To Log File Only
$Dummy = WriteLine($ExecLogFHndle, $InfoText + Chr(13) + Chr(10))
If $Dummy = 0
Else
$ContextError = "Writing in Log File : " + $ExecLogFName
$NoError = @Error
$StringError = @SError
$Fatal = 0
Gosub ErrorHandling
EndIf
Case 1
; Report To ... Who Knows ...
EndSelect

EndFunction

Function LDel($CharacterType)
Select
Case $CharacterType = "-"
$Dummy = Info("-------------------------------------------------------------------------------")
Case $CharacterType = "*"
$Dummy = Info("*********************************************")
Case $CharacterType = "="
$Dummy = Info("===============================================================================")
Case 1
EndSelect
EndFunction


;****************************************************************************
; :JobToDo
;****************************************************************************
:JobToDo

$FileAndDirCount = 0
$Location = ""
$Path = $DeviceName + $Location

$Dummy = Dir($Path + "\*.")
If $Dummy <> "" AND @Error = 0
While @Error = 0 AND $Dummy <> ""
$FileAndDirCount = $FileAndDirCount + 1
$Dummy = Dir()
Loop
? "File(s) And Dir(s) : " + "$FileAndDirCount" + " found"
Else
? @ERROR
EndIf

Return

And Here are the Parms Files :

_Connect-Parms.KiX
code:
 
;**********************************************
;** Data File For Connect.KiX **
;** **
;** No Space near equal sign please ...**
;** Alternatively Type Only A Space ...**
;**********************************************
;* InfoMode=0 No Message
;* InfoMode=1 Screen Only
;* InfoMode=2 Screen & Log File
;* InfoMode=3 Log File Only
;* If Ommitted Default Value : 0
;* If Incorrect Default Value : 1
;*
;* Remark : $InfoMode Affectation in Command Line
;* Overrides This Setting
InfoMode=2


;* OperatorName=[AnyDomainUserName]
;* If Ommitted, Default value : ScriptExecutorUserName
;* If Incorrect : Script Aborts
;OperatorName=

;* OperatorPwd=[Guess What!]]
;OperatorPwd=

;* DeviceName=[Letter AND Double Dot, Range D: <-> Y:]
;* If Ommitted, Default value : Scanned By Script
;* If Incorrect : Script Aborts
;DeviceName

;* Proc2Execute=[ProcName Label]
;* If Ommitted : Script Executes Ist Internal Proc : JobToDo
;* If Incorrect: Script Aborts
;Proc2Execute=Dummy3.Kix

_Connect-ResourceNames.KiX :

code:
 
ResourceNames List to Connect ...

\\Server1\Site
\\Server2\Site
\\Server3\Site
\\Server4\Site

When I run this modified script, it finally hangs, with a "Send Report to MicroSoft" Window and ends just when begining to execute the JobToDo Proc. for the second server ...

I suspect a not so well documented issue in MS Database concerning a problem with the use of credentials.

Here are some details about the context :

- Servers 1 to 4 are located in differnet NT Domains.
- The account which launches the scripts is reconized as admin in these domains (ie the same job under nt command line [Net Use ...], no account/password is required).
- Script is launched from an XP console.
- KiXtart Version is 4.10 Beta 1 Build 084 (4.10.0.0)

Someone will perhaps explain that in intelligible words and sentences ...

Unless it is absolutely Off Topic, isn't It ?

(MCA: complete subject)

[ 17 June 2002, 19:49: Message edited by: MCA ]