如何在程序启动后不打开控制台的情况下从批处理文件中运行程序?

时间:2021-11-20 00:01:59

For the moment my batch file look like this:

目前我的批处理文件如下所示:

myprogram.exe param1

The program starts but the DOS Window remains open. How can I close it?

程序启动但DOS窗口仍然打开。我怎么能关闭它?

11 个解决方案

#1


146  

You can use the exit keyword. Here is an example from one of my batch files:

您可以使用exit关键字。以下是我的一个批处理文件中的示例:

start myProgram.exe param1
exit

#2


215  

Use the start command to prevent the batch file from waiting for the program. Just remember to put a empty double quote in front of the program you want to run after "Start". For example, if you want to run Visual Studio 2012 from a batch command:

使用start命令可防止批处理文件等待程序。只需记住在“开始”之后在要运行的程序前放置一个空的双引号。例如,如果要从批处理命令运行Visual Studio 2012:

Start ""  "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

notice the double quote after start.

开始后注意双引号。

#3


50  

Look at the START command, you can do this:

查看START命令,您可以这样做:

START rest-of-your-program-name

For instance, this batch-file will wait until notepad exits:

例如,此批处理文件将一直等到记事本退出:

@echo off
notepad c:\test.txt

However, this won't:

但是,这不会:

@echo off
start notepad c:\test.txt

#4


28  

From my own question:

从我自己的问题:

start /b myProgram.exe params...

works if you start the program from an existing DOS session.

如果从现有DOS会话启动程序,则有效。

If not, call a vb script

如果没有,请调用vb脚本

wscript.exe invis.vbs myProgram.exe %*

The Windows Script Host Run() method takes:

Windows Script Host Run()方法采用:

  • intWindowStyle : 0 means "invisible windows"
  • intWindowStyle:0表示“隐形窗口”

  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish
  • bWaitOnReturn:false表示您的第一个脚本不需要等待第二个脚本完成

Here is invis.vbs:

这是invis.vbs:

set args = WScript.Arguments
num = args.Count

if num = 0 then
    WScript.Echo "Usage: [CScript | WScript] invis.vbs aScript.bat <some script arguments>"
    WScript.Quit 1
end if

sargs = ""
if num > 1 then
    sargs = " "
    for k = 1 to num - 1
        anArg = args.Item(k)
        sargs = sargs & anArg & " "
    next
end if

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False

#5


18  

You should try this. It starts the program with no window. It actually flashes up for a second but goes away fairly quickly.

你应该试试这个。它启动程序没有窗口。它实际上闪烁了一秒钟,但相当快地消失了。

start "name" /B myprogram.exe param1

#6


18  

This is the only thing that worked for me when I tried to run a java class from a batch file:

当我尝试从批处理文件中运行java类时,这是唯一有用的东西:

start "cmdWindowTitle" /B "javaw" -cp . testprojectpak.MainForm

启动“cmdWindowTitle”/ B“javaw”-cp。 testprojectpak.MainForm

You can customize the start command as you want for your project, by following the proper syntax:

您可以按照正确的语法自定义项目所需的启动命令:

Syntax
      START "title" [/Dpath] [options] "command" [parameters]

Key:
   title      : Text for the CMD window title bar (required)
   path       : Starting directory
   command    : The command, batch file or executable program to run
   parameters : The parameters passed to the command

Options:
   /MIN       : Minimized
   /MAX       : Maximized
   /WAIT      : Start application and wait for it to terminate
   /LOW       : Use IDLE priority class
   /NORMAL    : Use NORMAL priority class
   /HIGH      : Use HIGH priority class
   /REALTIME  : Use REALTIME priority class

   /B         : Start application without creating a new window. In this case
                ^C will be ignored - leaving ^Break as the only way to 
                interrupt the application
   /I         : Ignore any changes to the current environment.

   Options for 16-bit WINDOWS programs only

   /SEPARATE   Start in separate memory space (more robust)
   /SHARED     Start in shared memory space (default)

#7


12  

How to solve "space problem" and local dependencies:

如何解决“空间问题”和本地依赖关系:

@echo off
cd "C:\Program Files\HeidiSQL"
start heidisql.exe

cd "C:\Program Files (x86)\Google\Chrome\Application"
start chrome.exe

exit

#8


0  

My solution to do this from the GUI:

我的解决方案是从GUI执行此操作:

  1. Create a shortcut to the program you want to run;

    创建要运行的程序的快捷方式;

  2. Edit the shortcut's properties;

    编辑快捷方式的属性;

  3. Change the TARGET field to %COMSPEC% /C "START "" "PROGRAMNAME"";

    将TARGET字段更改为%COMSPEC%/ C“START”“”PROGRAMNAME“”;

  4. Change the RUN field to minimized.

    将RUN字段更改为最小化。

Ready! See how you like it...

准备!看看你喜欢它...

PS: Program parameters can be inserted in between the two final quotation marks; the PROGRAMNAME string can be either a filename, a relative or an absolute path -- if you put in an absolute path and erase the drive letter and semicolon, then this will work in a thumbdrive no matter what letter the host computer assigns to it... (also, if you place the shortcut in the same folder and precede the program filename in PROGRAMNAME with the %CD% variable, paths will always match; same trick can be used in START IN field).

PS:程序参数可以插入两个最终引号之间; PROGRAMNAME字符串可以是文件名,相对路径或绝对路径 - 如果你输入绝对路径并删除驱动器号和分号,那么无论主机分配给它的是什么字母,这都可以在thumbdrive中工作。 ..(另外,如果将快捷方式放在同一文件夹中并在PROGRAMNAME中的程序文​​件名前面加上%CD%变量,则路径将始终匹配;相同的技巧可以在START IN字段中使用)。

#9


0  

If this batch file is something you want to run as scheduled or always; you can use windows schedule tool and it doesn't opens up in a window when it starts the batch file.

如果此批处理文件是您希望按计划或始终运行的内容;您可以使用Windows计划工具,它在启动批处理文件时不会在窗口中打开。

To open Task Scheduler:

要打开任务计划程序:

  • Start -> Run/Search -> 'cmd'
  • 开始 - >运行/搜索 - >'cmd'

  • Type taskschd.msc -> enter
  • 输入taskschd.msc - >输入

From the right side, click Create Basic Task and follow the menus.

在右侧,单击“创建基本任务”并按照菜单操作。

Hope this helps.

希望这可以帮助。

#10


0  

Here is my preferred solution. It is taken from an answer to a similar question.

这是我的首选解决方案。它取自对类似问题的回答。

Use a VBS Script to call the batch file:

使用VBS脚本调用批处理文件:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path\to\your\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing

Copy the lines above to an editor and save the file with .VBS extension.

将上面的行复制到编辑器并使用.VBS扩展名保存文件。

#11


0  

I was having this problem and the following worked for me:

我遇到了这个问题,以下内容对我有用:

run myprogram.exe param1

#1


146  

You can use the exit keyword. Here is an example from one of my batch files:

您可以使用exit关键字。以下是我的一个批处理文件中的示例:

start myProgram.exe param1
exit

#2


215  

Use the start command to prevent the batch file from waiting for the program. Just remember to put a empty double quote in front of the program you want to run after "Start". For example, if you want to run Visual Studio 2012 from a batch command:

使用start命令可防止批处理文件等待程序。只需记住在“开始”之后在要运行的程序前放置一个空的双引号。例如,如果要从批处理命令运行Visual Studio 2012:

Start ""  "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

notice the double quote after start.

开始后注意双引号。

#3


50  

Look at the START command, you can do this:

查看START命令,您可以这样做:

START rest-of-your-program-name

For instance, this batch-file will wait until notepad exits:

例如,此批处理文件将一直等到记事本退出:

@echo off
notepad c:\test.txt

However, this won't:

但是,这不会:

@echo off
start notepad c:\test.txt

#4


28  

From my own question:

从我自己的问题:

start /b myProgram.exe params...

works if you start the program from an existing DOS session.

如果从现有DOS会话启动程序,则有效。

If not, call a vb script

如果没有,请调用vb脚本

wscript.exe invis.vbs myProgram.exe %*

The Windows Script Host Run() method takes:

Windows Script Host Run()方法采用:

  • intWindowStyle : 0 means "invisible windows"
  • intWindowStyle:0表示“隐形窗口”

  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish
  • bWaitOnReturn:false表示您的第一个脚本不需要等待第二个脚本完成

Here is invis.vbs:

这是invis.vbs:

set args = WScript.Arguments
num = args.Count

if num = 0 then
    WScript.Echo "Usage: [CScript | WScript] invis.vbs aScript.bat <some script arguments>"
    WScript.Quit 1
end if

sargs = ""
if num > 1 then
    sargs = " "
    for k = 1 to num - 1
        anArg = args.Item(k)
        sargs = sargs & anArg & " "
    next
end if

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False

#5


18  

You should try this. It starts the program with no window. It actually flashes up for a second but goes away fairly quickly.

你应该试试这个。它启动程序没有窗口。它实际上闪烁了一秒钟,但相当快地消失了。

start "name" /B myprogram.exe param1

#6


18  

This is the only thing that worked for me when I tried to run a java class from a batch file:

当我尝试从批处理文件中运行java类时,这是唯一有用的东西:

start "cmdWindowTitle" /B "javaw" -cp . testprojectpak.MainForm

启动“cmdWindowTitle”/ B“javaw”-cp。 testprojectpak.MainForm

You can customize the start command as you want for your project, by following the proper syntax:

您可以按照正确的语法自定义项目所需的启动命令:

Syntax
      START "title" [/Dpath] [options] "command" [parameters]

Key:
   title      : Text for the CMD window title bar (required)
   path       : Starting directory
   command    : The command, batch file or executable program to run
   parameters : The parameters passed to the command

Options:
   /MIN       : Minimized
   /MAX       : Maximized
   /WAIT      : Start application and wait for it to terminate
   /LOW       : Use IDLE priority class
   /NORMAL    : Use NORMAL priority class
   /HIGH      : Use HIGH priority class
   /REALTIME  : Use REALTIME priority class

   /B         : Start application without creating a new window. In this case
                ^C will be ignored - leaving ^Break as the only way to 
                interrupt the application
   /I         : Ignore any changes to the current environment.

   Options for 16-bit WINDOWS programs only

   /SEPARATE   Start in separate memory space (more robust)
   /SHARED     Start in shared memory space (default)

#7


12  

How to solve "space problem" and local dependencies:

如何解决“空间问题”和本地依赖关系:

@echo off
cd "C:\Program Files\HeidiSQL"
start heidisql.exe

cd "C:\Program Files (x86)\Google\Chrome\Application"
start chrome.exe

exit

#8


0  

My solution to do this from the GUI:

我的解决方案是从GUI执行此操作:

  1. Create a shortcut to the program you want to run;

    创建要运行的程序的快捷方式;

  2. Edit the shortcut's properties;

    编辑快捷方式的属性;

  3. Change the TARGET field to %COMSPEC% /C "START "" "PROGRAMNAME"";

    将TARGET字段更改为%COMSPEC%/ C“START”“”PROGRAMNAME“”;

  4. Change the RUN field to minimized.

    将RUN字段更改为最小化。

Ready! See how you like it...

准备!看看你喜欢它...

PS: Program parameters can be inserted in between the two final quotation marks; the PROGRAMNAME string can be either a filename, a relative or an absolute path -- if you put in an absolute path and erase the drive letter and semicolon, then this will work in a thumbdrive no matter what letter the host computer assigns to it... (also, if you place the shortcut in the same folder and precede the program filename in PROGRAMNAME with the %CD% variable, paths will always match; same trick can be used in START IN field).

PS:程序参数可以插入两个最终引号之间; PROGRAMNAME字符串可以是文件名,相对路径或绝对路径 - 如果你输入绝对路径并删除驱动器号和分号,那么无论主机分配给它的是什么字母,这都可以在thumbdrive中工作。 ..(另外,如果将快捷方式放在同一文件夹中并在PROGRAMNAME中的程序文​​件名前面加上%CD%变量,则路径将始终匹配;相同的技巧可以在START IN字段中使用)。

#9


0  

If this batch file is something you want to run as scheduled or always; you can use windows schedule tool and it doesn't opens up in a window when it starts the batch file.

如果此批处理文件是您希望按计划或始终运行的内容;您可以使用Windows计划工具,它在启动批处理文件时不会在窗口中打开。

To open Task Scheduler:

要打开任务计划程序:

  • Start -> Run/Search -> 'cmd'
  • 开始 - >运行/搜索 - >'cmd'

  • Type taskschd.msc -> enter
  • 输入taskschd.msc - >输入

From the right side, click Create Basic Task and follow the menus.

在右侧,单击“创建基本任务”并按照菜单操作。

Hope this helps.

希望这可以帮助。

#10


0  

Here is my preferred solution. It is taken from an answer to a similar question.

这是我的首选解决方案。它取自对类似问题的回答。

Use a VBS Script to call the batch file:

使用VBS脚本调用批处理文件:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path\to\your\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing

Copy the lines above to an editor and save the file with .VBS extension.

将上面的行复制到编辑器并使用.VBS扩展名保存文件。

#11


0  

I was having this problem and the following worked for me:

我遇到了这个问题,以下内容对我有用:

run myprogram.exe param1