Hide Command Window of .BAT file that Executes Ano

2019-01-13 07:17发布

This is a batch file in Windows.

Here is my .bat file

@echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"

"C:\ThirdParty.exe"

This works fine except the .bat file leaves the command window open the whole time the "ThirdParty" application is running.
I need the command window to close.

I would use the short-cut for the application but I must be able to run this copy command first (it actually changes which data base and server to use for the application).

The ThirdParty application does not allow the user to change the source of the db or the application server.

We're doing this to allow users to change from a test environment to the production environment.

14条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-13 07:38

Using start works for me:

@echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe

EDIT: Ok, looking more closely, start seems to interpret the first parameter as the new window title if quoted. So, if you need to quote the path to your ThirdParty.exe you must supply a title string as well.

Examples:

:: Title not needed:
start C:\ThirdParty.exe

:: Title needed
start "Third Party App" "C:\Program Files\Vendor\ThirdParty.exe"
查看更多
一夜七次
3楼-- · 2019-01-13 07:38

Using start works fine, unless you are using a scripting language. Fortunately, there's a way out for Python - just use pythonw.exe instead of python.exe:

:: Title not needed:
start pythonw.exe application.py

In case you need quotes, do this:

:: Title needed
start "Great Python App" pythonw.exe "C:\Program Files\Vendor\App\application.py"
查看更多
该账号已被封号
4楼-- · 2019-01-13 07:39

I used this to start a cmd file from c#:

        Process proc = new Process();
        proc.StartInfo.WorkingDirectory = "myWorkingDirectory";
        proc.StartInfo.FileName = "myFileName.cmd";
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        proc.Start();
        proc.WaitForExit();
查看更多
Rolldiameter
5楼-- · 2019-01-13 07:44

Please use this one, the above does not work. I have tested in Window server 2003.

@echo off 
copy "C:\Remoting.config-Training" "C:\Remoting.config"
Start /I "" "C:\ThirdParty.exe"
exit
查看更多
不美不萌又怎样
6楼-- · 2019-01-13 07:48

Compile the batch file to an executable using Batch2Exe http://www.f2ko.de/programs.php?lang=en&pid=b2e. Use the "Invisible Window" option.

查看更多
疯言疯语
7楼-- · 2019-01-13 07:51

You can create a VBS script that will force the window to be hidden.

Set WshShell = WScript.CreateObject("WScript.Shell") 
obj = WshShell.Run("""C:\Program Files (x86)\McKesson\HRS 
Distributed\SwE.bat""", 0) 
set WshShell = Nothing 

Then, rather than executing the batch file, execute the script.

查看更多
登录 后发表回答