我怎样才能运行Windows批处理文件,但隐藏命令窗口? [英] How can I run a windows batch file but hide the command window?

查看:287
本文介绍了我怎样才能运行Windows批处理文件,但隐藏命令窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何运行Windows批处理文件,但隐藏命令窗口?我不想给CMD.EXE正在执行的文件时,屏幕上是可见的。这可能吗?

How can I run a windows batch file but hiding the command window? I dont want cmd.exe to be visible on screen when the file is being executed. Is this possible?

推荐答案

如果你写一个非托管程序并使用的CreateProcess API,那么你应该初始化类型的 lpStartupInfo 参数的STARTUPINFO wShowWindow struct的字段的 SW_HIDE 并没有忘记用 STARTF_USESHOWWINDOW 标记中的的dwFlags 领域。另一种方法是使用 CREATE_NO_WINDOW dwCreationFlags 参数。同样的伎俩工作也与的ShellExecute 并的的ShellExecuteEx 功能。

If you write an unmanaged program and use CreateProcess API then you should initialize lpStartupInfo parameter of the type STARTUPINFO so that wShowWindow field of the struct is SW_HIDE and not forget to use STARTF_USESHOWWINDOW flag in the dwFlags field of STARTUPINFO. Another method is to use CREATE_NO_WINDOW flag of dwCreationFlags parameter. The same trick work also with ShellExecute and ShellExecuteEx functions.

如果你写的管理应用您应该遵循从<一个建议href=\"http://blogs.msdn.com/b/jmstall/archive/2006/09/28/createnowindow.aspx\">http://blogs.msdn.com/b/jmstall/archive/2006/09/28/createnowindow.aspx:初始化的ProcessStartInfo CreateNoWindow = TRUE UseShellExecute = FALSE 和那么作为一个参数使用。酷似的情况下,你可以设置属性 WindowStyle 的ProcessStartInfo ProcessWindowStyle.Hidden 代替或连同 CreateNoWindow = TRUE

If you write a managed application you should follows advices from http://blogs.msdn.com/b/jmstall/archive/2006/09/28/createnowindow.aspx: initialize ProcessStartInfo with CreateNoWindow = true and UseShellExecute = false and then use as a parameter of . Exactly like in case of you can set property WindowStyle of ProcessStartInfo to ProcessWindowStyle.Hidden instead or together with CreateNoWindow = true.

可以使用VBS脚本您开始wcsript.exe。在脚本中可以使用的CreateObject(WScript.Shell),然后的 0作为第二个( intWindowStyle )参数运行。见<一href=\"http://www.robvanderwoude.com/files/runnhide_vbs.txt\">http://www.robvanderwoude.com/files/runnhide_vbs.txt举个例子。我可以使用Kix, PowerShell的等。

You can use a VBS script which you start with wcsript.exe. Inside the script you can use CreateObject("WScript.Shell") and then Run with 0 as the second (intWindowStyle) parameter. See http://www.robvanderwoude.com/files/runnhide_vbs.txt as an example. I can continue with Kix, PowerShell and so on.

如果你不想写这样 CMDOW /你可以使用任何程序的任何现有的工具 RUN / HIDC:\\ SomeDir \\ MyBatch.cmd,<一个href=\"http://www.howtogeek.com/howto/windows/hide-flashing-command-line-and-batch-file-windows-on-startup/\">hstart / NOWINDOW / D = C:\\脚本C:\\脚本\\ mybatch.bat, HSTART / NOCONSOLEbatch_file_1.bat里面做完全一样的。我相信,你会发现更多的这样那样的免费的实用工具。

If you don't want to write any program you can use any existing utility like CMDOW /RUN /HID "c:\SomeDir\MyBatch.cmd", hstart /NOWINDOW /D=c:\scripts "c:\scripts\mybatch.bat", hstart /NOCONSOLE "batch_file_1.bat" which do exactly the same. I am sure that you will find much more such kind of free utilities.

在某些情况下还设置了的工作目录以一些地方的路径是很重要的(的%SystemRoot(比如从UNC路径的开始) %\\ SYSTEM32 工作总是)。这对于使用任何的重要从上面开始隐藏一批上市的变种。

In some scenario (for example starting from UNC path) it is important to set also a working directory to some local path (%SystemRoot%\system32 work always). This can be important for usage any from above listed variants of starting hidden batch.

这篇关于我怎样才能运行Windows批处理文件,但隐藏命令窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆