Davy <
Da...@me.com> typed:
You can give the Run-Method the command to wait for return. That is the
syntax:
intResult = object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
bWaitOnReturn is an optional boolean value indicating whether the script
should wait for the program to finish executing before continuing to the
next statement in your script. If set to *true*, script execution stops
until the program has finished, and Run evaluates any error code returned
by the program. If this parameter is set to *false*, what is the precon-
dition, or if omitted, the Run method returns immediately after starting
the program without any result. But you can get the same effect if you
call this Method in order to obtain a return code, then this method
behaves as bWaitOnReturn is set to true.
This command returns immediately:
wshShell.Run "NTBackup.exe", wshMinimezed
This both commands wait until the end of execution of the called program:
intReturn = wshShell.Run("NTBackup.exe")
wshShell.Run "NTBackup.exe", , True
But I am not sure whether this is the solution for your problem. Post
your code so that I can see that spaghetti.
That is a script I wrote 3 years ago for an automatic backup of a user's
folder at the end of each session:
'########################### Sicherung.vbs ############################
Rem von h.r.roesler
' The script saves a folder hierarchy, it was tested with
' Windows 7 Ultimate edition.
' Syntax:
' CScript.exe [path]Sicherung.vbs <Source Folder> <Target Folder>
' CScript.exe C:\Windows\Sicherung.vbs C:\Users\Public R:\backup
' If the name of a folder contains blank characters, it must be
' enclosed in quotation marks.
Option Explicit
Const SysFolder = 1, SRC = 0, DST = 1, ZIEL = 2
Dim fso, strFldr(2), strArgs, strCmd, str, i
Set fso = CreateObject("Scripting.FileSystemObject")
strCmd = fso.BuildPath(fso.GetSpecialFolder(SysFolder), "RoboCopy.exe")
If Not(fso.FileExists(strCmd)) Then strCmd = "RoboCopy.exe"
If WScript.Arguments.Count > 1 Then
strFldr(SRC) = WScript.Arguments(SRC)
strFldr(DST) = WScript.Arguments(DST)
End If
With CreateObject("WScript.Shell")
If Not(fso.FolderExists(strFldr(SRC))) Then
.PopUp "Source Folder " & strFldr(SRC) & " doesn't exist!", _
30, WScript.ScriptName, vbExclamation Or vbSystemModal
WScript.Quit
End If
Select Case .PopUp("Should the user's folder " & strFldr(SRC) & _
" be saved?", 10, WScript.ScriptName, _
vbQuestion Or vbYesNo Or vbSystemModal)
Case vbNo:
Case Else:
str = .ExpandEnvironmentStrings("%USERNAME%") ' Pfad basteln
strFldr(DST) = fso.BuildPath(strFldr(DST), str & "\" & _
fso.GetBaseName(strFldr(SRC)))
str = fso.BuildPath(fso.GetParentFolderName(strFldr(DST)), _
fso.GetBaseName(WScript.ScriptName) & ".log")
If InStr(str, " ") > 0 Then str = """" & str & """"
strArgs = " /MIR /W:0 /R:0 /REG /FFT /NP /TEE /LOG:" & str
If Not(fso.FolderExists(strFldr(DST))) Then
For Each str In Split(strFldr(DST), "\")
strFldr(ZIEL) = strFldr(ZIEL) & str & "\"
If Not(fso.FolderExists(strFldr(ZIEL))) Then
'WScript.Echo "Erzeuge " & strFldr(ZIEL)
fso.CreateFolder strFldr(ZIEL)
End If
Next
End If
For i = SRC To DST ' Backslash am Ende eines Pfades
Do While Right(strFldr(i), 1) = "\" ' entfernen
strFldr(i) = Left(strFldr(i), Len(strFldr(i)) - 1)
Loop
If InStr(strFldr(i), " ") > 0 Then
strFldr(i) = """" & strFldr(i) & """"
End If
Next
strCmd = strCmd & " " & strFldr(SRC) & " " & strFldr(DST)
'WScript.Echo strCmd & strArgs
With .Exec(strCmd & strArgs)
Do Until .StdOut.AtEndOfStream
WScript.StdOut.WriteLine .StdOut.ReadLine
WScript.Sleep 0
Loop
End With
End Select
End With
'########################### Sicherung.vbs ############################
--
ЯR