【问题标题】:Disable popup messages in CMD start command在 CMD 启动命令中禁用弹出消息
【发布时间】:2018-10-02 06:48:17
【问题描述】:

我想创建一个尝试以静默方式启动程序的 Windows BAT 或 VBS。如果程序不存在,我希望它静默终止,不显示任何警报窗口。

我正在尝试以下名为 startSilently.bat 的蝙蝠:

@echo off
start %1

当我在 CMD 中输入 startSilently.bat chrome 时,Google Chrome 会正常打开。

但是当我输入startSilently.bat nonexistent 时,我会收到一条弹出消息告诉我:

Windows 找不到“不存在”。确保您输入了名称 正确,然后重试。

我希望这条消息没有出现。有没有办法做到这一点?

注意:我不能使用call 代替start,因为我不知道程序安装在哪里。

【问题讨论】:

    标签: windows batch-file cmd vbscript


    【解决方案1】:

    可以通过这种方式在 .vbs 中完成:

    On Error Resume Next
    WScript.CreateObject("WSCript.shell").run WScript.Arguments.Unnamed(0) 
    

    然后你就这样称呼它:

    cscript scriptname.vbs appname
    

    如果您希望在静默启动中希望应用程序最小化启动,则可以添加 intWindowStyle 参数,其值 = 7,如下所示:

    On Error Resume Next
    WScript.CreateObject("WSCript.shell").run WScript.Arguments.Unnamed(0),7
    

    ...但这可能不适用于所有应用程序。例如,记事本将开始最小化,但不是 chrome。

    【讨论】:

    • 程序不存在时脚本是否可以返回1?它总是返回 0。
    • 最后添加:If Err.Number0 Then WScript.Quit 1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2016-12-28
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    相关资源
    最近更新 更多