我可以运行带有隐藏cmd窗口的Windows批处理文件但是看到批处理启动的程序吗?

时间:2016-05-12 08:23:15

标签: windows batch-file cmd scripting

我想以隐藏的方式启动批处理文件。 This discussion非常清楚地说明了如何完成:使用CreateProcess API函数。使用此方法,我的启动批处理脚本不可见。

问题是,批处理内部调用的程序(exes)也是隐藏的!

我的目标是隐藏已启动的批处理窗口,但显示批处理内部调用的应用程序的窗口。

有可能吗?如果是这样,怎么样?我可以使用CreateProcess功能,还是需要另外一个功能?

2 个答案:

答案 0 :(得分:0)

下一步评论批处理脚本显示了可行的方法

  • 另一个批处理脚本:
    • cliParser.bat只列出所有提供的参数;
    • cliParseArg.bat将相同的设置为errorlevel参数计数(从零开始,因此永远不会重复0exit /b %i%;
  • GUI应用程序:运用常见的calcnotepad可执行文件;
  • 一个Win32控制台应用程序:cliParser.exe cliParser.bat已在C++中重写;

来自一个不可见的命令行窗口。给出如何以异步方式和同步方式运行的示例(即等到被叫应用程序结束)。

@ECHO OFF
SETLOCAL EnableExtensions

rem       STDOUT output is invisible if this script runs in a hidden window 
wmic OS get LocalDateTime

rem       another batch script            asynchronously            => visible
start "batch asyn" cmd /K ""D:\bat\cliParser.bat" par1 %* "par 3""

rem errorlevel clear: by virtue of Dave Benham in reply to http://superuser.com/a/649329/376602
(call )
rem       another batch script             synchronously            => visible
start "batch synchr" /WAIT cmd /K "("D:\bat\cliParseArg.bat" par1 %* "par 3"&pause&exit /B %%%%errorlevel%%%%)"
rem `pause` command in above line is merely for debugging purposes to ensure that window is visible 
echo cliParseArg.bat parameter count=%errorlevel%
echo(

rem       a GUI application               asynchronously            => visible
start "" calc.exe

rem       a GUI application                synchronously            => visible
notepad.exe

rem       a console application           asynchronously            => visible
start "CApp asyn" cmd /K ""D:\bat\cliParser.exe" rap1 %* "rap 3""

rem       a console application            synchronously            => visible
start "CApp synchr" /WAIT cmd /K "("D:\bat\cliParser.exe" arg1 %* "arg 3"&exit /B)"

rem       STDOUT output is invisible if this script runs in a hidden window 
cmd /C wmic OS get LocalDateTime

首先从可见的cmd窗口调用然后在隐藏的窗口中调用输出::

==> D:\bat\SO\37181230.bat "xx yy"
LocalDateTime
20160512195221.499000+120

cliParseArg.bat parameter count=4

LocalDateTime
20160512195244.958000+120

==> Wscript D:\VB_scripts\runhidden.vbs "D:\bat\SO\37181230.bat" "A1 B2"

==>

runhidden.vbs改编自Rob van der Woude's script其中

  • strArguments = strArguments & " " & WScript.Arguments(i)行已更改为
  • strArguments = strArguments & " """ & WScript.Arguments(i) & """"

答案 1 :(得分:0)

这应该可以解决问题,请在批处理文件中使用此代码来启动EXE。

 @echo off
 title GEO-START v2

 REM  #############################################################
 REM ## GEO-START ## starts any file any location with variables. ##
 REM  #############################################################
 REM ##
 REM "start-and-wait-yes-no" variable, Y is yes, N is no. 
 REM ##
 REM "var" variable, "/silent" or "/y". ## The /y variable is grait for "ms self extracting cabinet files" CAB.exe.
 REM ##
 REM "silent" variable, 0 will set the "var" variable to true and trys to run hidden.
 REM "silent" variable, 1 will set the "var" variable to false.
 REM ##
 REM "GEO-START" variable, the name and location of the file you want to start.
 REM ################################################
 set Y=true
 set N=Wscript.Quit
 REM ##############




 REM #####################
 REM ## variables to set ##

 set start-and-wait-yes-no=%Y%
 set var=/silent
 set silent=1
 set GEO-START=Winamp3 v9.1.exe

 echo Set WshShell = WScript.CreateObject("WScript.Shell") > GEO-START.vbs && echo WSHShell.Run chr(34) + "%GEO-START%" + chr(34) + " %var%",%silent%,%start-and-wait-yes-no% >> GEO-START.vbs && cscript GEO-START.vbs && del GEO-START.vbs
 Exit