我使用批处理文件一次静默安装不同的程序。 看起来像这样(摘录):
REM ------------------------------- ALIAS -------------------------------
SET APPS=\\ser-nas\Distribution\APPLICATIONS
SET BUREAU=C:\Users\%username%\Desktop
SET BUREAUPUBLIC=C:\Users\Public\Desktop
SET QUICKLAUNCH=C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch
REM ------------------------------ VERSIONS ------------------------------
SET Version_CCleaner=504
SET Version_Firefox=36.0.4
SET Version_FlashPlayer=17x32
SET Version_LibreOffice=4.3.7
SET Version_AdobeReader=11003
SET Version_PDFCreator=2_0_2
SET Version_7Zip=920
SET Version_TightVNC=2.7.10
SET Version_VLC=2.1.5
REM ---------------------------- ARCHITECTURE ----------------------------
Set _Bitness=64
IF %PROCESSOR_ARCHITECTURE% == x86 (
IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set _Bitness=32
)
REM ---------------------------- INSTALLATION ----------------------------
echo Installation de CCleaner v%Version_CCleaner%...
start /wait %APPS%\System\Cleaners\ccsetup%Version_CCleaner%.exe /S /L=1036
echo Installation de Mozilla Firefox v%Version_Firefox%...
start /wait %APPS%\Internet\"Firefox Setup %Version_Firefox%.exe" -ms
echo Installation de Flash Player v%Version_FlashPlayer% pour Firefox...
start /wait %APPS%\FlashPlayer\17\Firefox\install_flashplayer%Version_FlashPlayer%_mssd_aaa_aih.exe -install
我的问题是...... 如何编写一个脚本来检测存储在文件夹中的每个程序的最新版本以进行安装?
到目前为止,我必须在执行之前手动更新批处理中的版本号。我希望批处理能够自动查找特定文件夹中存在的最新版本。
感谢您的帮助。
答案 0 :(得分:0)
下一个脚本可以给出提示。
@ECHO OFF >NUL
SETLOCAL enableextensions
SET "APPS=\\ser-nas\Distribution\APPLICATIONS"
SET "APPS=D:\downloads"
call :getVersion Version_Gimp "%APPS%" "gimp-" "-setup-1.exe"
echo debug3 Version_Gimp=%Version_Gimp%
call :getVersion Version_CCleaner "%APPS%\System\Cleaners" "ccsetup" ".exe"
echo debug4 Version_CCleaner=%Version_CCleaner%
call :getVersion Version_Firefox "%APPS%\Internet" "Firefox Setup " ".exe"
call :getVersion Version_FlashPlayer "%APPS%\FlashPlayer\17\Firefox" "install_flashplayer" "_mssd_aaa_aih.exe"
ENDLOCAL
goto :eof
:getVersion
:: %1 by reference call example
:: %1 = variable name Version_FlashPlayer
:: %2 = "setup_folder" "%APPS%\FlashPlayer\17\Firefox"
:: %3 = "setup_exe_prefix" "install_flashplayer"
:: %4 = "setup_exe_suffix" "_mssd_aaa_aih.exe"
::
SETLOCAL enableextensions EnableDelayedExpansion
set "version="
echo debug1 "%~2\%~3*%~4"
FOR /F "delims=" %%G in ('dir /B /O:N "%~2\%~3*%~4" 2^>NUL') do (
set "version=%%~G"
)
if defined version if not "%~3"=="" set "version=!version:%~3=!"
if defined version if not "%~4"=="" set "version=!version:%~4=!"
)
echo debug2 %1=%version%
ENDLOCAL&set "%1=%version%"&goto :eof
:getVersion
过程以/O:N
dir
命令切换(按名称排序)返回最高版本;对于特定的(更复杂的)版本控制方案来说还不够......
<强>输出强>:
==>D:\bat\StackOverflow\30046694.bat
debug1 "D:\downloads\gimp-*-setup-1.exe"
debug2 Version_Gimp=2.8.14
debug3 Version_Gimp=2.8.14
debug1 "D:\downloads\System\Cleaners\ccsetup*.exe"
debug2 Version_CCleaner=
debug4 Version_CCleaner=
debug1 "D:\downloads\Internet\Firefox Setup *.exe"
debug2 Version_Firefox=
debug1 "D:\downloads\FlashPlayer\17\Firefox\install_flashplayer*_mssd_aaa_aih.exe"
debug2 Version_FlashPlayer=