How to avoid cmd.exe command window

I have a command like:

cmd.exe /c ping 1.1.1.1 -n 1 -w 10000 && echo second command goes here 

But when it is executed, the command window opens. Is there a way to avoid the command window from appearing?

PS: I can not remove cmd.exe from there. As you can see, I am trying to link two teams one by one on the same line.

Thanks.

Edit: Sorry. This is not a bat file. I want to execute 2 commands in "UninstallString" msiexec. I tried so many things that my question got a little carried away.

Command:

 msiexec <product> <package> && reg delete /xxx 
+4
source share
4 answers

The easiest option is to start a minimized thing. Label purpose:

 cmd /c START /MIN \path\to\test.bat 

or

 cmd /c START /MIN cmd /k ( ping 1.1.1.1 -w 10000 -n 1 && @ECHO All OK) 

It is not hidden or something else, but it does not appear on the desktop or, worse, steals focus.

If you want the window to go away by itself, "cmd / c ..." will do this. "cmd / k ..." will leave the window open.

Plan B is mentioned by @CodyGray in a published SU link. There are programs that do not open windows, such as wperl, pythonw, or wscript (initially available on Windows). If you can transfer your command to one of these things, then you can effectively double-click the icon and run it silently.

If Perl were available, I would, of course, agree to this, because you can create fairly powerful single-line files that do not require the creation of other files.

 wperl -MWin32 -MNet::Ping -e "$p=Net::Ping->new('icmp',10000); if ($p->ping('192.168.1.1')) { Win32::MsgBox('Ping Successful', 1 + MB_OK, 'All Good'); }" 

In your example, you combine the teams together, the last one is the notification. If you do not want the window to be open for the first command, it would be inconvenient to do this for the second when you notify the user of something. After invoking the "cmd / c start cmd / c @echo Everything OK" process, this would probably do, but using the CMD windows to notify the user was probably not the kind that the HCI guys would welcome.

+7
source

No, all batch files open in command prompt windows; this has nothing to do with the presence of cmd.exe in your particular file. A batch file is just a few command line commands, one per line.

I do not understand why you write test.bat , how you do it. I would rather expect

 ping 1.1.1.1 -n 1 -w 10000 echo second command goes here 

If, for some reason, you really need to use only one line, you can just do

 ping 1.1.1.1 -n 1 -w 10000 && echo second command goes here 
+2
source

As Andreas Rejbrand already explained, the command line window is not connected with an explicit call to cmd.exe in your script, but with the execution of the .bat script itself. (And, despite your requirement, you did not provide any evidence of the need to explicitly call cmd.exe . The whole point in the .bat script is the command commands together.)

However, the silentbatch program that Paul Miner and I wrote can execute batch scripts and suppress the command window. To use it, you will need to create a Windows shortcut that calls silentbatch.exe test.bat and double-clicks it, instead of double- test.bat .

+2
source

You can also create a shortcut for you batch script, and then select in the properties to start the application is minimized. It explains: CNET: how to automatically run a minimized program on Windows

Step 1: Right-click the shortcut for the program you want to minimize and select "Properties."
Step 2. Click on the drop-down menu in the "Run" section.
Step 3: Select Minimize, then click OK.

+1
source

Source: https://habr.com/ru/post/1487566/


All Articles