views:

1526

answers:

3

I'm using WinRAR SFX module to create an installation, and use its presetup option to run some preliminary tests.

Since wscript can only accept vbs file, and not the script itself, I first run "cmd /c echo {...script code...} > setup.vbs", and then I run "wscript setup.vbs". The run of the first cmd command opens a brief command window, and I would really like to avoid this. I thought of using RunDll32 to write this data, but couldn't find any suitable API to use.

Can anyone think of a way to bypass it and create a small file with a small VBScript text without opening a Command Prompt window?

Thanks a lot,

splintor

+2  A: 

Is the script code already in a file? If so,

You can use the TYPE command to send the script to a file:

TYPE [script_file] > setup.vbs

or COPY the script file:

COPY [script_file] setup.vbs

If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):

START /B cmd /c echo {...script code...} > setup.vbs
Patrick Cuff
type, copy and start are all internal commands of cmd, so cmd must first run, which means a command prompt window will be displayed :(
splintor
How are you first running "cmd /c echo {...script code...} > setup.vbs"? From your tags it looks like you're doing this from a command line or batch script.
Patrick Cuff
WinRAR allows you to specify commands to run before the extraction. WinRAR is running it, probably using ShellExecute or something similar, but I have no real control over it.
splintor
If you say "cmd /c echo {...script code...} > setup.vbs" in some WinRAR script or dialog, you should be able to say "START /B cmd /c echo {...script code...} > setup.vbs". Does that work (sorry, I don't have WinRAR to try this myself).
Patrick Cuff
We don't exactly say "cmd /c echo..." - we say "%windir%\system32\cmd.exe /c echo...". I guess WinRAR is using something like ShellExecute.
splintor
Note that cmd is very different from start. There is a cmd.exe executable, but there is no Start.exe. "cmd /c echo" will work from Start->Run, but "Start /b cmd /c echo" won't, as Start is an internal command of the cmd.exe interperter.
splintor
BTW, if you are really interested, you can download WinRAR from http://www.rarlab.com/download.htm and play with it - it is a Trialware. And thanks for the great efforts to help me solve this problem.
splintor
I download and am trying to recreate the issue. My presetup command doesn't run; what does your look like? What's the setup command look like? This script goes in the Archive Comment, correct?
Patrick Cuff
It doesn't look like you can do what you want without some exe that can run commands without a console. There's a free one here: http://www.ntwind.com/software/utilities/hstart.html. Call this instead of cmd.exe.
Patrick Cuff
The problem is that my self-extract zip file is an installation, and I cannot assume hstart.exe is installed on the machine this installation is run on.I guess my only resort is to ask WinRAR support for a new option to create a file with a given text. This way I can create a vbs file and run it.
splintor
A: 

Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.

You can call another VBScript from VBScript like this:

Set WSHShell = CreateObject("WScript.Shell") 
WSHShell.Run "wscript d:\setup.vbs, ,True

See this MSDN link for the syntax of the Run command.

Patrick Cuff
Thanks Patrick for this additional attempt.However, I'm using presetup because extraction can take a long time, and I want my tests to stop the extraction before it begins if prerequisites are not met.It's a real shame wscript.exe doesn't have an option similar to "cmd /c".
splintor
A: 

is it also possible to create am autorun .vbs file?

Can you explain what you mean in more details?WinRAR doesn't have an autorun files mechanism, but a setup and presetup command lines.
splintor