wget玩linux的都不陌生,而windows图形化的下载工具,满天飞。
工作中有个项目需求很简单,就是要实现一键安装。
最简单的就是统一打包做个安装包,但这个问题就面临着安装包会随着打包程序的累加而变得越来越庞大,这就尴尬了
所以就想到api拉取(http协议)后自动安装,随就百度了一下,发现wget和bat两个程序(这里的bat是个二进制程序,不是bat脚本),wget和linux用法相同没什么区别,而我在github上看到了bat的二进制程序也可以实现相同功能,本着熟悉wget不易出现问题,就选择了wget。
wget for windows 下载地址:https://eternallybored.org/misc/wget/
这个bat脚本,没有好好规划,写的有点随意,也懒得的去优化了,简单说思路:通过先通过注册表检测软件是否安装,然后wget下载缺失软件,下载后安装。
1.适配winxp、win7、及win10
2.根据系统检测缺失软件,并通过http协议下载安装(adober、net3.5及自的程序软件)
3.下载、安装状态判断
注:wget和这个脚本要放在同一个目录,且wget要适配xp要选择1.13版本
脚本如下,未做dos的完美优化,懒得折腾了,如有需要自行完善!!!
@echo off
::DOS标签
title ffing一键安装
::判断是否多个进程
tasklist /v /fo csv | findstr /i "ffing一键安装" |find /c /v "" >%temp%\pidnum.txt
set /p PIDNUM=<%temp%\pidnum.txt
if %PIDNUM%==1 (goto INIT ) else (goto EXIT1)
:EXIT
exit
:INIT
::定义检测结果变量
set FFING_CHECK=%temp%\FFING_SOFTCHECK.txt
echo start>%FFING_CHECK%
::定义当前脚本环境变量
set FFING_ONEKEY_DIR=C:\FFING_Onekey
path %path%;%FFING_ONEKEY_DIR%
::####################判断windows版本###########################
ver |find " 5.1" >nul
if not errorlevel 1 goto WindowsXP
ver |find " 6.0" >nul
if not errorlevel 1 goto WindowsVista
ver |find " 6.1" >nul
if not errorlevel 1 goto Windows7
ver |find " 10." >nul
if not errorlevel 1 goto Windows10
(echo 查询版本失败,NET环境请使用根据系统版本安装)
goto AU
:WindowsXP
echo WIN版本:Windows XP
echo WIN版本:Windows XP >>%FFINGCHECK%
goto AU
:WindowsVista
echo WIN版本:Windows Vista
echo WIN版本:Windows Vista >>%FFINGCHECK%
goto AU
:Windows7
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 7-X86) else (goto 7-X64)
:7-X86
echo WIN版本:Windows7 X86
echo WIN版本:Windows7 X86 %FFINGCHECK%
goto AU
:7-X64
echo WIN版本:Windows7 X64
echo WIN版本:Windows7 X64 %FFINGCHECK%
goto AU
:Windows10
ver|find " 10.0.10240" >nul
if not errorlevel 1 goto Windows1507
ver|find " 10.0.10586" >nul
if not errorlevel 1 goto Windows1151
ver|find " 10.0.14393" >nul
if not errorlevel 1 goto Windows1607
ver|find " 10.0.15063" >nul
if not errorlevel 1 goto Windows1703
ver|find " 10.0.16299" >nul
if not errorlevel 1 goto Windows1709
ver|find " 10.0.17134" >nul
if not errorlevel 1 goto Windows1803
ver|find " 10.0.17763" >nul
if not errorlevel 1 goto Windows1809
ver|find " 10.0.18362" >nul
if not errorlevel 1 goto Windows1903
ver|find " 10.0.18363" >nul
if not errorlevel 1 goto Windows1909
ver|find " 10.0.19041" >nul
if not errorlevel 1 goto Windows2004
ver|find " 10.0.19042" >nul
if not errorlevel 1 goto Windows20H2
ver|find " 10.0.19043" >nul
if not errorlevel 1 goto Windows21H1
ver|find " 10.0.19044" >nul
if not errorlevel 1 goto Windows21H2
(echo 查询版本失败,NET环境请使用根据系统版本安装)
:Windows1507
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1507-X86) else (goto 1507-X64)
:1507-X86
echo WIN版本:Windows10(1507) X86
echo WIN版本:Windows10(1507) X86>>%FFINGCHECK%
goto AU
:1507-X64
echo WIN版本:Windows10(1507) X64
echo WIN版本:Windows10(1507) X64>>%FFINGCHECK%
goto AU
:Windows1511
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1511-X86) else (goto 1511-XX64)
:1511-XX86
echo WIN版本:Windows10(1511) X86
echo WIN版本:Windows10(1511) X86>>%FFINGCHECK%
goto AU
:1511-XX64
echo WIN版本:Windows10(1511) X64
echo WIN版本:Windows10(1511) X64>>%FFINGCHECK%
goto AU
:Windows1607
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1607-X86) else (goto 1607-X64)
:1607-X86
echo WIN版本:Windows10(1607) X86
echo WIN版本:Windows10(1607) X86>>%FFINGCHECK%
goto AU
:1607-X64
echo WIN版本:Windows10(1607) X64
echo WIN版本:Windows10(1607) X64>>%FFINGCHECK%
goto AU
:Windows1703
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1703-X86) else (goto 1703-X64)
:1703-X86
echo WIN版本:Windows10(1703) X86
echo WIN版本:Windows10(1703) X86>>%FFINGCHECK%
goto AU
:1703-X64
echo WIN版本:Windows10(1703) X64
echo WIN版本:Windows10(1703) X64>>%FFINGCHECK%
goto AU
:Windows1709
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1709-X86) else (goto 1709-X64)
:1709-X86
echo WIN版本:Windows10(1709) X86
echo WIN版本:Windows10(1709) X86>>%FFINGCHECK%
goto AU
:1709-X64
echo WIN版本:Windows10(1709) X64
echo WIN版本:Windows10(1709) X64>>%FFINGCHECK%
goto AU
:Windows1803
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1803-X86) else (goto 1803-X64)
:1803-X86
echo WIN版本:Windows10(1803) X86
echo WIN版本:Windows10(1803) X86>>%FFINGCHECK%
goto AU
:1803-X64
echo WIN版本:Windows10(1803) X64
echo WIN版本:Windows10(1803) X64>>%FFINGCHECK%
goto AU
:Windows1809
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1809-X86) else (goto 1809-X64)
:1809-X86
echo WIN版本:Windows10(1809) X86
echo WIN版本:Windows10(1809) X86>>%FFINGCHECK%
goto AU
:1809-X64
echo WIN版本:Windows10(1809) X64
echo WIN版本:Windows10(1809) X64>>%FFINGCHECK%
goto AU
:Windows1903
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1903-X86) else (goto 1903-X64)
:1903-X86
echo WIN版本:Windows10(1903) X86
echo WIN版本:Windows10(1903) X86>>%FFINGCHECK%
goto AU
:1903-X64
echo WIN版本:Windows10(1903) X64
echo WIN版本:Windows10(1903) X64>>%FFINGCHECK%
goto AU
:Windows1909
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 1909-X86) else (goto 1909-X64)
:1909-X86
echo WIN版本:Windows10(1909) X86
echo WIN版本:Windows10(1909) X86>>%FFINGCHECK%
goto AU
:1909-X64
echo WIN版本:Windows10(1909) X64
echo WIN版本:Windows10(1909) X64>>%FFINGCHECK%
goto AU
:Windows2004
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 2004-X86) else (goto 2004-X64)
:2004-X86
echo WIN版本:Windows10(2004) X86
echo WIN版本:Windows10(2004) X86>>%FFINGCHECK%
goto AU
:2004-X64
echo WIN版本:Windows10(2004) X64
echo WIN版本:Windows10(2004) X64>>%FFINGCHECK%
goto AU
:Windows20H2
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 20H2-X86) else (goto 20H2-X64)
:20H2-X86
echo WIN版本:Windows10(20H2) X86
echo WIN版本:Windows10(20H2) X86>>%FFINGCHECK%
goto AU
:20H2-X64
echo WIN版本:Windows10(20H2) X64
echo WIN版本:Windows10(20H2) X64>>%FFINGCHECK%
goto AU
:Windows21H1
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 21H1-X86) else (goto 21H1-X64)
:21H1-X86
echo WIN版本:Windows10(21H1) X86
echo WIN版本:Windows10(21H1) X86>>%FFINGCHECK%
goto AU
:21H1-X64
echo WIN版本:Windows10(21H1) X64
echo WIN版本:Windows10(21H1) X64>>%FFINGCHECK%
goto AU
:Windows21H2
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (goto 21H2-X86) else (goto 21H2-X64)
:21H2-X86
echo WIN版本:Windows10(21H2) X86
echo WIN版本:Windows10(21H2) X86>>%FFINGCHECK%
goto AU
:21H2-X64
echo WIN版本:Windows10(21H2) X64
echo WIN版本:Windows10(21H2) X64>>%FFINGCHECK%
goto AU
:AU
::################判断角色权限######################
path %path%;%FFING_ONEKEY_DIR%
::判断操作系统
ver|findstr XP >/nul
if %errorlevel%==0 (goto XP ) else (goto WIN )
:WIN
::获取管理员权限(仅适用win7/win10)
%1 start "" mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
goto CHECK
:XP
::获取管理员权限(仅适用xp)
echo.
goto CHECK
:CHECK
::IE一键设置 ###################################################################
echo ---------------------------------------------------------------
echo 启动IE自动设置
echo ---------------------------------------------------------------
start C:\FFING_Onekey\IE_auto.bat
:PING-WAIT
ping -n 2 127.0.0.1>/nul
tasklist /v /fo csv |findstr "IE_auto.bat" >/nul
if %errorlevel%==0 goto PING-WAIT
echo ---------------------------------------------------------------
echo IE自动设置完成
echo ---------------------------------------------------------------
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
::title
title ffing一键安装
path %path%;%FFING_ONEKEY_DIR%
::定义变量
set REG000="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
set REGNET="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"
echo 插件名称 检测结果
echo ---------------------------------------------------------------
::监测adober是否安装
reg query %REG000% /s |find /i "Adobe Reader" >/nul
if %errorlevel%==0 ( goto YES1 ) else ( goto NO1 )
:NO1
if exist "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe" ( goto YES1 ) else ( goto NO11 )
:YES1
echo AdobeReade已安装
echo AdobeReade已安装>>%FFINGCHECK%
goto NET3.5
:NO11
echo AdobeReade 未安装
echo AdobeReade 未安装>>%FFINGCHECK%
goto NET3.5
:NET3.5
::监测是否安装net3.5
reg query %REGNET% /s |find /i "v3.5" >/nul
if %errorlevel%==0 (
echo net3.5环境已安装
echo net3.5环境已安装>>%FFINGCHECK%
) else (
echo net3.5环境 未安装
echo net3.5环境 未安装>>%FFINGCHECK%
)
::监测是否安装FFING
reg query %REG000% /s |find /i "FFINGPlugin" >/nul
if %errorlevel%==0 (
echo ffing插件已安装
echo ffing插件已安装>>%FFINGCHECK%
) else (
echo ffing插件 未安装
echo ffing插件 未安装>>%FFINGCHECK%
)
echo ---------------------------------------------------------------
echo.
::判断现有状态是否全部都已经安装,如全部安装跳至结束
type %FFINGCHECK%|findstr "已安装"|find /c /v "" >%temp%\softnum.txt
set /P SOFTNUM=<%temp%\softnum.txt
if %SOFTNUM%==3 goto OVER
echo 根据检测结果,开始自动下载安装所需软件
echo 保存路径:C:\
echo.
::################自动安装流程#######################################################################################################################################
::服务器地址
SET IPADD=huawei.ffing.cn
SET URL=http://%IPADD%:5244/d
SET FFINGVER=社会渠道
echo 当前版本:%FFINGVER%
::判断网络是否畅通
ping -n 2 %IPADD% >>%FFINGCHECK%
type %FFINGCHECK%|find /i "TTL=" >/nul
if %errorlevel%==0 goto NET-TRUE
:NET-ERROR
echo 网络异常,无法继续下载安装,请确认网络或渠道版本
echo 按任意键退出
ping -n 5 127.0.0.1 >/nul
pause >/nul
exit
:NET-TRUE
::检测信息分配变量
path %path%;%FFING_ONEKEY_DIR%
(SET /P INFO=&SET /P WINVER=&SET /P ADOBER_INFO=&SET /P NET3.5_INFO=&SET /P FFING_INFO=)<%FFINGCHECK%
::安装唯一区别在于net3.5版本及位数
SET APP1=adobeReader9.exe
SET APP1_DOWN=%URL%/ClientUpgrade/downLoadFile/%APP1%
::Net3.5名称
::XP
SET APP2-XP=XP-Net3.5_src.exe
::
SET APP2_DOWN-XP=%URL%/ClientUpgrade/downLoadFile/%APP2-XP%
::WIN10名称范例:WIN10_1909_X86-Net3.5_src.exe
type %FFINGCHECK%|find "X86" >/nul
if %errorlevel%==0 (set BIT=X86) else (set BIT=X64)
SET APP2-WIN10=WIN10_%WINVER:~16,4%_%BIT%-Net3.5_src.exe
::
SET APP2_DOWN-WIN10=%URL%/ClientUpgrade/downLoadFile/%APP2-WIN10%
SET APP3=FFINGupgrade-now.exe
::
SET APP3_DOWN=%URL%/ClientUpgrade/downLoadFile/%APP3%
:Download-APP1
::判断APP1是否安装
type %FFINGCHECK%|find "AdobeReade已安装" >/nul
if %errorlevel%==0 goto Download-APP2
echo ----------------------------------------------------------------------------
echo 开始下载:%APP1% 【如下载长时间卡死,请按键盘Ctrl+C,可继续下载】
echo ----------------------------------------------------------------------------
echo 下载地址:%APP1_DOWN%
wgetX86.exe %APP1_DOWN% -P C:\FFING_Onekey -O --no-check-certificate
if %errorlevel%==0 (goto TRUE1 ) else (goto FALSE1)
:TRUE1
echo ----------------------------------------------------------------------------
echo 下载完成:%APP1%
echo ----------------------------------------------------------------------------
goto Install-APP1
:FALSE1
echo.
echo.
echo.
echo ----------------------------------------------------------------------------
echo %APP1%下载失败,4秒后重试
echo ----------------------------------------------------------------------------
ping 127.0.0.1 >/nul
goto Download-APP2
:Install-APP1
echo ----------------------------------------------------------------------------
echo 正在安装:%APP1%
echo ----------------------------------------------------------------------------
%APP1% /sPB /rs /l /msi"/qb-! /norestart ALLUSERS=2 EULA_ACCEPT=YES SUPPRESS_APP_LAUNCH=YES"
:Install-APP1-WAIT
ping -n 1 127.0.0.1 >/nul
tasklist |findstr %APP1% >/nul
if %errorlevel%==0 goto Install-APP1-WAIT
echo.
echo ----------------------------------------------------------------------------
echo %APP1%安装完成
echo ----------------------------------------------------------------------------
echo.
echo.
echo.
:Download-APP2
::判断APP2是否安装
type %FFINGCHECK%|find "net3.5环境已安装" >/nul
if %errorlevel%==0 goto Download-APP3
echo ----------------------------------------------------------------------------
echo 开始下载:%APP2% 【如下载长时间卡死,请按键盘Ctrl+C,可继续下载】
echo ----------------------------------------------------------------------------
::判断系统
type %FFINGCHECK% |findstr "XP" >/nul
if %errorlevel%==0 goto APP2_DOWN-XP
type %FFINGCHECK% |findstr "Vista" >/nul
if %errorlevel%==0 goto APP2_DOWN-XP
type %FFINGCHECK% |findstr "Windows10" >/nul
if %errorlevel%==0 goto APP2_DOWN-WIN10
:APP2_DOWN-XP
set APP2=%APP2-XP%
goto APP2_DOWN
:APP2_DOWN-WIN10
set APP2=%APP2-WIN10%
goto APP2_DOWN
:APP2_DOWN
echo 下载地址%URL%/ClientUpgrade/downLoadFile/%APP2%
wgetX86.exe %URL%/ClientUpgrade/downLoadFile/%APP2% -P C:\FFING_Onekey --no-check-certificate
if %errorlevel%==0 (goto TRUE2 ) else (goto FALSE2)
:TRUE2
echo ----------------------------------------------------------------------------
echo 下载完成:%APP2%
echo ----------------------------------------------------------------------------
goto Install-APP2
:FALSE2
echo.
echo.
echo.
echo ----------------------------------------------------------------------------
echo %APP2%下载失败,网络异常,4秒后重新下载
echo ----------------------------------------------------------------------------
ping 127.0.0.1 >/nul
goto Download-APP2
:Install-APP2
echo ----------------------------------------------------------------------------
echo 正在安装:%APP2%
echo ----------------------------------------------------------------------------
start %APP2%
:Install-APP2-WAIT
ping -n 1 127.0.0.1 >/nul
tasklist |findstr %APP2% >/nul
if %errorlevel%==0 goto Install-APP2-WAIT
:Net3.5-CMD_CHECK
tasklist /v /fo csv | findstr /i "Net3.5_src-install" >/nul
if %errorlevel%==0 ( goto TRUE-WAIT ) else ( goto FALSE-GO)
:TRUE-WAIT
ping -n 1 127.0.0.1 >/nul
goto Net3.5-CMD_CHECK
:FALSE-GO
::判断Win10Net3.5安装状态
type %FFINGCHECK%|find "Net3.5安装成功" >/nul
if %errorlevel%==0 (
echo.
echo ----------------------------------------------------------------------------
echo %APP2%安装完成
echo ----------------------------------------------------------------------------
echo.
echo.
echo.
goto Download-APP3
) else (
echo.
echo ----------------------------------------------------------------------------
echo !!! %APP2%安装失败,缺少依赖框架,无法正常使用ffing插件!!!
echo ----------------------------------------------------------------------------
echo 安装失败,请联系终端管理员手动修复Net3.5后,再执行本程序!!!
echo ----------------------------------------------------------------------------
echo 安装失败,请联系终端管理员手动修复Net3.5后,再执行本程序!!!
echo ----------------------------------------------------------------------------
echo 安装失败,请联系终端管理员手动修复Net3.5后,再执行本程序!!!
echo ----------------------------------------------------------------------------
echo.
echo.
echo.
echo 按任意键退出
pause >/nul
exit
)
:Download-APP3
::判断APP3是否安装
type %FFINGCHECK%|find "ffing插件已安装" >/nul
if %errorlevel%==0 goto OVER
echo ----------------------------------------------------------------------------
echo 开始下载:%APP3% 【如下载长时间卡死,请按键盘Ctrl+C,可继续下载】
echo ----------------------------------------------------------------------------
echo 下载地址:%APP3_DOWN%
wgetX86.exe %APP3_DOWN% -P C:\FFING_Onekey --no-check-certificate
if %errorlevel%==0 (goto TRUE3 ) else (goto FALSE3)
:TRUE3
echo ----------------------------------------------------------------------------
echo 下载完成:%APP3%
echo ----------------------------------------------------------------------------
goto Install-APP3
:FALSE3
echo.
echo.
echo.
echo ----------------------------------------------------------------------------
echo %APP3%下载失败,4秒后重试
echo ----------------------------------------------------------------------------
ping 127.0.0.1 >/nul
goto Download-APP3
:Install-APP3
echo ----------------------------------------------------------------------------
echo 正在安装:%APP3%
echo ----------------------------------------------------------------------------
start %APP3%
:WARN-FFING
echo.
echo ----------------------------------------------------------------------------
echo 请手动点击"下一步"安装FFING插件,待安装结束,自动刷新检测结果
echo ----------------------------------------------------------------------------
echo.
:Install-APP3-WAIT
ping -n 1 127.0.0.1 >/nul
tasklist |findstr %APP3% >/nul
if %errorlevel%==0 goto Install-APP3-WAIT
goto OVER-CHECK
:OVER
echo.
echo ----------------------------------------------------------------------------
echo ffing全部安装结束
echo ----------------------------------------------------------------------------
echo.
echo 按任意键退出
pause >/nul
exit
:OVER-CHECK
::检测FFING安装进程是否存在
tasklist |findstr %APP3% >/nul
if %errorlevel%==0 goto WARN-FFING
::定义变量
set REG000="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
set REGNET="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"
echo 插件名称 检测结果 版本:%FFINGVER%
echo ---------------------------------------------------------------
::监测adober是否安装
reg query %REG000% /s |find /i "Adobe Reader" >/nul
if %errorlevel%==0 ( goto YES1 ) else ( goto NO1 )
:NO1
if exist "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe" ( goto YES1 ) else ( goto NO11 )
:YES1
echo AdobeReade已安装
goto NET3.5
:NO11
echo AdobeReade 未安装
goto NET3.5
:NET3.5
::监测是否安装net3.5
reg query %REGNET% /s |find /i "v3.5" >/nul
if %errorlevel%==0 (
echo net3.5环境已安装
) else (
echo net3.5环境 未安装
)
::监测是否安装FFING
reg query %REG000% /s |find /i "FFINGPlugin" >/nul
if %errorlevel%==0 (
echo ffing插件已安装
) else (
echo ffing插件 未安装
)
echo ---------------------------------------------------------------
echo 已刷新检测结果,按任意键退出
pause >/nul
exit
拓展:
dos美化问题,可自行百度,或者直接dos转图形化
发表评论