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条回答
Deceive 欺骗
2楼-- · 2019-01-13 07:51

run it under a different user. assuming this is a windows box, create a user account for scheduled tasks. run it as that user. The command prompt will only show for the user currently logged in.

查看更多
贼婆χ
3楼-- · 2019-01-13 07:52

To make the command window of a .bat file that executes a .exe file exit out as fast as possible, use the line @start before the file you're trying to execute. Here is an example:

(insert other code here) @start executable.exe (insert other code here)

You don't have to use other code with @start executable.exe.

查看更多
我只想做你的唯一
4楼-- · 2019-01-13 07:53

Or you can use :

Start /d "the directory of the executable" /b "the name of the executable" "parameters of the executable" %1 ( %1 is if a file, is passed to your executable, for example, notepad.exe foo.txt, here %1 is "foo.txt".

The /b parameters of the start command does this : "Starts an application without opening a new Command Prompt window. CTRL+C handling is ignored unless the application enables CTRL+C processing. Use CTRL+BREAK to interrupt the application." Which is exactly what we want.

查看更多
等我变得足够好
5楼-- · 2019-01-13 07:56

Create a .vbs file with this code:

CreateObject("Wscript.Shell").Run "your_batch.bat",0,True

This .vbs will run your_batch.bat hidden.

Works fine for me.

查看更多
仙女界的扛把子
6楼-- · 2019-01-13 07:56

Great tip. It works with batch files that are running a java program also.

start javaw -classpath "%CP%" main.Main
查看更多
一纸荒年 Trace。
7楼-- · 2019-01-13 07:58

Try this:

@echo off 
copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe
exit
查看更多
登录 后发表回答