cmd窗口隐藏

@echo off
if “%1”==“h” goto begin
start mshta vbscript:createobject(“wscript.shell”).run("""%~nx0"" h",0)(window.close)&&exit
:begin
::以下为正常批处理命令,不可含有pause set/p等交互命令

如果双击一个批处理,等价于参数为空,而一些应用程序需要参数,比如在cmd窗口输入shutdowm -s -t 0,其中-s -t 0就为参数。shutdown为%0,-s为%1,-t为%2,以此类推。
第一行我们先跳过,看第二行,表示利用mshta创建一个vbs程序,内容为:createobject(“wscript.shell”).run(……).如果运行的批处理名为a.bat,在C:\下,那%0代表C:\a.bat,%~nx0代表a.bat。h极为参数%1,0表示隐藏运行。由于你双击运行,故第一次批处理%1为空,if不成立,转而运行下一句。然后再次打开自己,并传递参数h,此时if成立,跳转至begin开始运行。
这两行很经典,可以使批处理无窗口运行。
使用说明:
如有一个xxx.exe的cmd窗口程序,想要让它隐藏运行
1、新建一个 1.bat 内容如下:

@echo off
if “%1”==“h” goto begin
start mshta vbscript:createobject(“wscript.shell”).run("""%~nx0"" h",0)(window.close)&&exit
:begin
xxx.exe
2、双击1.bat,这样xxx.exe就会默默的运行了

猜你喜欢

转载自blog.csdn.net/haodawei123/article/details/86238706
今日推荐