viniciussss
viniciussss

Reputation: 4652

Disable popup messages in CMD start command

I want to create a Windows BAT or VBS that tries to start a program silently. If the program does not exist, I would like it to terminate silently, without showing any alert window.

I am trying the following bat named startSilently.bat:

@echo off
start %1

When I type startSilently.bat chrome in CMD, Google Chrome opens as it should.

But when I type startSilently.bat nonexistent, then I get a popup message telling me:

Windows cannot find 'nonExistent'. Make sure you typed the name correctly, and then try again.

enter image description here

I wish this message did not show up. Is there a way to do this?

Note: I cannot use call instead of start because I don't know where the program is installed.

Upvotes: 0

Views: 2653

Answers (1)

Regis Desrosiers
Regis Desrosiers

Reputation: 565

It can be done in a .vbs this way:

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

You then call it like that:

cscript scriptname.vbs appname

If in your start silently desire you prefer that the application start minimized, you can add the intWindowStyle argument with value = 7 like that:

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

... but that may not work with all applications. For example, notepad will start minimized but not chrome.

Upvotes: 1

Related Questions