隐藏执行另一个.EXE文件的.BAT文件的命令窗口

时间:2022-02-21 07:05:16

This is a batch file in Windows.

这是Windows中的批处理文件。

Here is my .bat file

这是我的.bat文件

@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.

这工作正常,除了.bat文件在“ThirdParty”应用程序运行的整个时间内打开命令窗口。我需要命令窗口关闭。

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.

ThirdParty应用程序不允许用户更改db或应用程序服务器的源。

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

我们这样做是为了允许用户从测试环境更改为生产环境。

14 个解决方案

#1


Using start works for me:

使用start对我来说:

@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.

编辑:好的,仔细观察,如果引用,start似乎将第一个参数解释为新的窗口标题。因此,如果您需要引用ThirdParty.exe的路径,您还必须提供标题字符串。

Examples:

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

:: Title needed
start "Third Party App" "C:\Program Files\Vendor\ThirdParty.exe"

#2


Create a .vbs file with this code:

使用以下代码创建.vbs文件:

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

This .vbs will run your_batch.bat hidden.

这个.vbs将运行your_batch.bat隐藏。

Works fine for me.

对我来说很好。

#3


Try this:

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

#4


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:

除非您使用脚本语言,否则使用start工作正常。幸运的是,Python有一条出路 - 只需使用pythonw.exe而不是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"

#5


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

很棒的提示。它适用于运行java程序的批处理文件。

start javaw -classpath "%CP%" main.Main

#6


I haven't really found a good way to do that natively, so I just use a utility called hstart which does it for me. If there's a neater way to do it, that would be nice.

我还没有真正找到一个很好的方法来做到这一点,所以我只是使用一个名为hstart的实用工具来为我做这件事。如果有一个更简洁的方法,这将是很好的。

#7


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

您可以创建一个强制隐藏窗口的VBS脚本。

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.

然后,执行脚本,而不是执行批处理文件。

#8


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

使用Batch2Exe http://www.f2ko.de/programs.php?lang=en&pid=b2e将批处理文件编译为可执行文件。使用“隐形窗口”选项。

#9


You might be interested in trying my silentbatch program, which will run a .bat/.cmd script, suppress creation of the Command Prompt window entirely (so you won't see it appear and then disappear), and optionally log the output to a specified file.

您可能有兴趣尝试我的silentbatch程序,该程序将运行.bat / .cmd脚本,完全禁止创建命令提示符窗口(因此您将看不到它然后消失),并可选择将输出记录到指定的文件。

#10


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.

在不同的用户下运行它。假设这是一个Windows框,请为计划任务创建一个用户帐户。以该用户身份运行它。命令提示符仅显示当前登录的用户。

#11


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

请使用此,以上不起作用。我在Window server 2003中测试过。

@echo off 
copy "C:\Remoting.config-Training" "C:\Remoting.config"
Start /I "" "C:\ThirdParty.exe"
exit

#12


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:

要使执行.exe文件的.bat文件的命令窗口尽快退出,请在您尝试执行的文件之前使用@start行。这是一个例子:

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

(在此处插入其他代码)@start executable.exe(在此处插入其他代码)

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

您不必在@start executable.exe中使用其他代码。

#13


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".

开始/ d“可执行文件的目录”/ b“可执行文件的名称”“可执行文件的参数”%1(%1是文件,如果传递给您的可执行文件,例如,notepad.exe foo.txt ,这里%1是“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.

start命令的/ b参数执行此操作:“在不打开新的命令提示符窗口的情况下启动应用程序。除非应用程序启用CTRL + C处理,否则将忽略CTRL + C处理。使用CTRL + BREAK中断应用程序。”这正是我们想要的。

#14


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

我用它来从c#启动一个cmd文件:

        Process proc = new Process();
        proc.StartInfo.WorkingDirectory = "myWorkingDirectory";
        proc.StartInfo.FileName = "myFileName.cmd";
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        proc.Start();
        proc.WaitForExit();

#1


Using start works for me:

使用start对我来说:

@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.

编辑:好的,仔细观察,如果引用,start似乎将第一个参数解释为新的窗口标题。因此,如果您需要引用ThirdParty.exe的路径,您还必须提供标题字符串。

Examples:

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

:: Title needed
start "Third Party App" "C:\Program Files\Vendor\ThirdParty.exe"

#2


Create a .vbs file with this code:

使用以下代码创建.vbs文件:

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

This .vbs will run your_batch.bat hidden.

这个.vbs将运行your_batch.bat隐藏。

Works fine for me.

对我来说很好。

#3


Try this:

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

#4


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:

除非您使用脚本语言,否则使用start工作正常。幸运的是,Python有一条出路 - 只需使用pythonw.exe而不是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"

#5


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

很棒的提示。它适用于运行java程序的批处理文件。

start javaw -classpath "%CP%" main.Main

#6


I haven't really found a good way to do that natively, so I just use a utility called hstart which does it for me. If there's a neater way to do it, that would be nice.

我还没有真正找到一个很好的方法来做到这一点,所以我只是使用一个名为hstart的实用工具来为我做这件事。如果有一个更简洁的方法,这将是很好的。

#7


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

您可以创建一个强制隐藏窗口的VBS脚本。

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.

然后,执行脚本,而不是执行批处理文件。

#8


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

使用Batch2Exe http://www.f2ko.de/programs.php?lang=en&pid=b2e将批处理文件编译为可执行文件。使用“隐形窗口”选项。

#9


You might be interested in trying my silentbatch program, which will run a .bat/.cmd script, suppress creation of the Command Prompt window entirely (so you won't see it appear and then disappear), and optionally log the output to a specified file.

您可能有兴趣尝试我的silentbatch程序,该程序将运行.bat / .cmd脚本,完全禁止创建命令提示符窗口(因此您将看不到它然后消失),并可选择将输出记录到指定的文件。

#10


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.

在不同的用户下运行它。假设这是一个Windows框,请为计划任务创建一个用户帐户。以该用户身份运行它。命令提示符仅显示当前登录的用户。

#11


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

请使用此,以上不起作用。我在Window server 2003中测试过。

@echo off 
copy "C:\Remoting.config-Training" "C:\Remoting.config"
Start /I "" "C:\ThirdParty.exe"
exit

#12


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:

要使执行.exe文件的.bat文件的命令窗口尽快退出,请在您尝试执行的文件之前使用@start行。这是一个例子:

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

(在此处插入其他代码)@start executable.exe(在此处插入其他代码)

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

您不必在@start executable.exe中使用其他代码。

#13


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".

开始/ d“可执行文件的目录”/ b“可执行文件的名称”“可执行文件的参数”%1(%1是文件,如果传递给您的可执行文件,例如,notepad.exe foo.txt ,这里%1是“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.

start命令的/ b参数执行此操作:“在不打开新的命令提示符窗口的情况下启动应用程序。除非应用程序启用CTRL + C处理,否则将忽略CTRL + C处理。使用CTRL + BREAK中断应用程序。”这正是我们想要的。

#14


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

我用它来从c#启动一个cmd文件:

        Process proc = new Process();
        proc.StartInfo.WorkingDirectory = "myWorkingDirectory";
        proc.StartInfo.FileName = "myFileName.cmd";
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        proc.Start();
        proc.WaitForExit();