How can I hide the command prompt window when launching a .BAT file?

Article:HOWTO7895  |  Created: 2007-08-24  |  Updated: 2007-08-24  |  Article URL http://www.symantec.com/docs/HOWTO7895
Article Type
How To



Question
How can I hide the command prompt window when launching a .BAT file?

Answer

The solution requires 2 batch files and a vb script.
launch.bat
invis.vbs
myfile.bat

1. In launch.bat (this files runs your program silently) enter...

wscript.exe "C:\path\invis.vbs" "myfile.bat"

2. In invis.vbs enter..

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

3.  In myfile.bat enter whatever you need.  Example:

"C:\windows\notepad.exe"

4. Next you need to execute launch.bat from the .MSI installation.

To execute a .BAT file in a Windows Installer installation, you will have to use a custom action. Do the following:
  1. In the .WSI file, select View > MSI Script..
  2. In the Installation Sequence list, click the location in the sequence where you want to place the custom action.
  3. Double-click the Execute Program from Path custom action on the Custom tab. The Execute Program from Path dialog displays.
  4. Populate the Details tab as follows:
    • Name: Enter a name for the custom action.
    • Property: Enter %COMSPEC. This is the environment variable that holds the location of the cmd.exe program.
    • Command Line: Enter "/c <path to .BAT>\<batchfile.BAT>" (replacing the text in <> with the path and name of your batch file. Enclose the path and batch file name in double quotes. The /c switch closes the cmd.exe window after the batch file executes. To execute the batch file and keep the cmd.exe window open, enter /k instead. (This can be useful for debugging batch files.)

      Note: The cmd.exe launches in the System directory by default. If your batch file executes actions in another directory, you must explicitly account for that in the batch file. For example, to list the files in c:\mydir, add a line to the batch file that reads 'cd c:\mydir'.
  5. Click OK.


Legacy ID



37659


Article URL http://www.symantec.com/docs/HOWTO7895


Terms of use for this information are found in Legal Notices