Juan
Juan

Reputation: 193

How to close the window of an executable launched from CMD without using TASKILL [BATCH]

I have made a basic BAT script to download updates from Avast virus database and then apply them by running the downloaded file.

@ECHO OFF

set downloadFolder=C:\Users\myuser\Downloads\Avast_updates

set downloadUrl=https://install.avcdn.net/vps18/vpsupd.exe

bitsadmin /transfer myAvastUpdates /download /priority normal ^
  "%downloadUrl%" "%downloadFolder%\vpsupd.exe" 

start /min "Update..." "%downloadFolder%\vpsupd.exe"

exit

Also, I have created a Windows task to run BAT every x hours.

Everything works correctly, but I want to know if there is any way to automatically close the executable window after the update process is finished.

enter image description here

It occurred to me to use TASKILL after x seconds, but that doesn't assure me that the update process finished in x seconds, sometimes it can take longer and sometimes less, plus I don't want to use that command in an program security installer.

Then it occurred to me to send an "Enter" through WshShell.SendKeys:

set SendKeys=CScript //nologo //E:JScript "%~F0"
cls
timeout /t 5 >nul
%SendKeys% "{ENTER}"

@end

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

But it did not work because that window does not close with "Enter" nor "ALT F4", it closes only if we click on "Done" or on the cross "x" to close the window (if it worked it would have the problem of setting the time again).

Is there a way to automatically close that window once the update process finishes?

Upvotes: 3

Views: 176

Answers (2)

Juan
Juan

Reputation: 193

With the help of @Stephan and @Gerhard, the code to download and update Avast was like this:

@ECHO OFF

set "downloadFolder=%userprofile%\Downloads\avast_updates"
set "downloadUrl=https://install.avcdn.net/vps18/vpsupd.exe"
 bitsadmin /transfer myAvastUpdates /download /priority normal ^
 "%downloadUrl%" "%downloadFolder%\vpsupd.exe" 

"%downloadFolder%\vpsupd.exe" /silent

exit

Upvotes: 0

Stephan
Stephan

Reputation: 56238

vpsupd.exe supports a /silent switch to suppress user interactions.

start /min isn't needed, as it just opens another cmd window, which in turn runs the executable. So just do:

vpsupd.exe /silent

Upvotes: 8

Related Questions