windows 运行批处理文件时隐藏 CMD

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15942555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:25:27  来源:igfitidea点击:

Hiding CMD While Running a Batch file

windowsbatch-file

提问by rajatgupta431

Can we hide Command Prompt when running a Batch file?

我们可以在运行批处理文件时隐藏命令提示符吗?

回答by BDM

This methodworks for me, however I also found thisand thisand this, etc, etc....

这个方法对我的作品,但我也发现了这个这个这个等等,等等......

回答by nino

I'm pretty confident I like this method the best. Copy and paste the code below into a .vbs file. From there you'll call the batch file... so make sure you edit the last line to specify the path and name of the batch file:

我非常有信心我最喜欢这种方法。将下面的代码复制并粘贴到 .vbs 文件中。从那里您将调用批处理文件...因此请确保编辑最后一行以指定批处理文件的路径和名称:

Const HIDDEN_WINDOW = 12 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") 
Set objStartup = objWMIService.Get("Win32_ProcessStartup") 

Set objConfig = objStartup.SpawnInstance_ 
objConfig.ShowWindow = HIDDEN_WINDOW 
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") 
errReturn = objProcess.Create("C:\PathOfFile\name.bat", null, objConfig, intProcessID)

It definitely worked for me. Comments are welcomed :)

它绝对对我有用。欢迎评论:)