1.

Solve : How do I run an .exe from CScript without creating a separate window??

Answer»

All the examples I have found are like this:

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & 7z a E:\ZipOut1 C:\TempBase"
Set oShell = Nothing

I would like to run several 7z commands in succession using CSCRIPT, but without creating a separate window for each one, and ideally without creating any new windows at all.
Code: [Select]
wscript.echo "Running 3 7zip operations"
wscript.echo
Run "7z a s:\ZipOut1 s:\Test-777\*"
Run "7z a s:\ZipOut2 s:\Test-777\*"
Run "7z a s:\ZipOut3 s:\Test-777\*"
wscript.echo
wscript.echo "Completed 7z operations"
wscript.echo
wscript.echo "Files produced:"
wscript.echo
Run "cmd /c dir s:\Zipout*"
wscript.echo
wscript.echo "Done"

' Runs an external program and pipes its output to
' the StdOut and StdErr streams of the current script.
' Returns the exit code of the external program.
Function Run (ByVal cmd)
Dim sh: Set sh = CreateObject("WScript.Shell")
Dim wsx: Set wsx = Sh.Exec(cmd)
Do
   Dim Status: Status = wsx.Status
   WScript.StdOut.Write wsx.StdOut.ReadAll()
   WScript.StdErr.Write wsx.StdErr.ReadAll()
   If Status <> 0 Then Exit Do
   WScript.Sleep 10
   Loop
Run = wsx.ExitCode
End Function


Code: [Select]Running 3 7zip operations


7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03

Scanning

Updating archive s:\ZipOut1.7z

Compressing  Readme.txt
Compressing  Windows Active Boot Disk.vmx
Compressing  Windows Active Boot Disk.vmxf

Everything is Ok

7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03

Scanning

Updating archive s:\ZipOut2.7z

Compressing  Readme.txt
Compressing  Windows Active Boot Disk.vmx
Compressing  Windows Active Boot Disk.vmxf

Everything is Ok

7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03

Scanning

Updating archive s:\ZipOut3.7z

Compressing  Readme.txt
Compressing  Windows Active Boot Disk.vmx
Compressing  Windows Active Boot Disk.vmxf

Everything is Ok

Completed 7z operations

Files produced:

 Volume in DRIVE S is USB-1
 Volume Serial Number is 2C51-AA7F

 Directory of s:\

24/10/2010  04:17 PM             1,561 ZipOut1.7z
24/10/2010  04:17 PM             1,561 ZipOut2.7z
24/10/2010  04:17 PM             1,561 ZipOut3.7z
               3 File(s)          4,683 bytes
               0 Dir(s)  156,771,778,560 bytes free

DoneI have tidied things up a bit; also I show how to use QUOTES around paths/filenames with SPACES. Inside strings, quotes need "escaping". That is,  to get one quote mark inside a VBScript string, you need two in the code that produces the string.

Code: [Select]wscript.echo "Running 3 7zip operations"
Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut1.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""
Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut2.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""
Run "7z a ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\7zip Archives\ZipOut3.7z"" ""S:\Test\Batch\After 16-10-2010\vbs-samewindow\Folder with spaces\*"""
wscript.echo "Done"

Function Run (ByVal cmd)
Set sh = CreateObject("WScript.Shell")
Set wsx = Sh.Exec(cmd)
Do
   Status = wsx.Status
   WScript.StdOut.Write wsx.StdOut.ReadAll()
   WScript.StdErr.Write wsx.StdErr.ReadAll()
   If Status <> 0 Then Exit Do
   WScript.Sleep 10
Loop
Run = wsx.ExitCode
End Function



Discussion

No Comment Found