Reputation: 1004
I am trying to make a simple batch file that finds an exe file in a folder and does a silent install of it. So far I have been unsuccessful with this:
for /r "%CD%\folder1\folder2\" %%a in (*.exe /sPB) do start "" "%%~fa"
Of course this gives me the error:
Windows cannot find 'E:\folder1\folder2\sPB'. Make sure you typed the name correctly, and then try again.
I know that the general command for the silent install would be something like:
mysoftware.exe /sPB
So where should I place the "silent install flags"? I realize that I should not put it after *.exe
.
Upvotes: 0
Views: 25535
Reputation: 411
Actually the flag is often put at the end after all the other parameters as in these examples below.
SET drive=%CD:~0,3%
%drive%InstallPackages\Notepad++\npp.7.3.1.Installer.x64.exe /S
%drive%InstallPackages\Windows_SDK\sdksetup.exe /features+ /q /norestart /ceip off
start /wait msiexec /l*v perl-log.txt /I %drive%InstallPackages\strawberry-perl\strawberry-perl-5.24.4.1-64bit.msi TARGETDIR="c:\" PERL_PATH="Yes" /qb
msiexec /i %drive%InstallPackages\Putty\putty-64bit-2017-03-08-installer.msi /q
%drive%InstallPackages\Visual C++\2012\vcredist_x86.exe /install /quiet /norestart
%drive%InstallPackages\Win-OpenSSL\Win32OpenSSL-1_0_2k.exe /SP- /VERYSILENT /NORESTART /NOICONS
But if it doesn't work at the end I'd try putting it immediately after the executable name. From the examples you will note that the flags (switches) can be different depending on the programmer and utility used to create the installer. But you shouldn't have to guess what they are. Usually all command line options (switches or flags) will be displayed if you run the setup or install (either in cmd.exe or from a windows shortcut) with "/?" or "/H" or "/help" after the executable name. Most setup/intallers will display something like this.
As you can see the most common switches for "silent" or "quiet" install are "/s" and "/q". I've also found this site very useful. Here are some other tips.
REM --- How to --- insert a comment: (start the line with REM)
REM This is a comment
REM --- How to --- display message to operator:
echo This is a message to operator
REM --- How to --- capture the local drive:
SET drive=%CD:~0,3%
REM --- How to --- Display a variable:
ECHO %drive%
REM --- How to --- direct code:
if <statement> (do something) else (do something else)
REM --- How to --- insert a label:
:START
REM --- How to --- Get user input:
SET /P answer=Are you sure you want to exit?[Y/N]?
REM --- How to --- jump to label: (avoid jumping forward)
IF /I "%answer%" EQU N GOTO START
REM --- How to --- Check for an existing directory: (must end in "\")
if not exist C:\Strawberry\perl\bin\ (do something)
REM --- How to --- use directory names having spaces:
if not exist C:\"Program Files"\Notepad++\ (do something)
REM --- How to --- verify a file exists: (you must check for the directory first)
if not exist C:\"Program Files"\CompanyName\ (
if not exist C:\"Program Files"\CompanyName\AppName.exe (do something)
)
REM --- How to --- suppress overwriting propmts: (Use the /Y flag)
copy %drive%InstallPackages\Tftpd64\*.* /Y C:\"Program Files"\Tftpd64\
REM --- How to --- change drive or directory: (in .bat file)
cd /D C:
chdir /D \Apache24\bin
REM --- How to --- compare files:
if fc C:\"Program Files"\CompanyName\AppName.ini %drive%InstallPackages\CompanyName\AppName.ini
REM --- How to --- hide/unhide output from operator:
@Echo off
@Echo on
Upvotes: 1
Reputation: 38613
Based on the fact you should know the location of your installer without the need to do a recursive search under folder1\folder2
, I'd suggest:
@Echo Off
CD /D "folder1\folder2" 2>Nul || Exit /B
For %%A In (AcroRdr*.exe) Do Start "" "%%A" /sPB /rs /msi
Although the method of installation should be the same either way:
For /R "folder1\folder2" %%A In (*.exe) Do Start "" "%%A" /sPB
Upvotes: 0