我想下载最新版本的 7z。
我的脚本下载当前版本,在其中我提供了必要的链接和文件名:
TITLE 7-ZIP
Reg.exe Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
:Download.
if %OS%==32BIT bitsadmin /Transfer 7-ZIPx86 /DOWNLOAD /Priority FOREGROUND https://www.7-zip.org/a/7z1900.exe %temp%\7z1900.exe
if %OS%==64BIT bitsadmin /Transfer 7-ZIPx64 /DOWNLOAD /Priority FOREGROUND https://www.7-zip.org/a/7z1900-x64.exe %temp%\7z1900-x64.exe
:Silent İnstall.
if %OS%==32BIT START /wait %temp%\7z1900.exe /S
if %OS%==64BIT START /wait %temp%\7z1900-x64.exe /S
:Temp Temizle.
if %OS%==32BIT DEL /F %temp%\7z1900.exe
if %OS%==64BIT DEL /F %temp%\7z1900-x64.exe
:Right click group ve CRC SHA remove.
Reg.exe add "HKCU\Software\7-Zip\Options" /v "MenuIcons" /t REG_DWORD /d "1" /f
Reg.exe add "HKCU\Software\7-Zip\Options" /v "ContextMenu" /t REG_DWORD /d "16247" /f
:END
TIMEOUT /T 5
如何始终下载最新版本,而不下载之前的版本?
答案1
- 获取当前版本的7-zip
history.txt
可以通过从中下载文件7-zip.org
并从中提取当前版本来创建直接链接以供使用Bitsadmin
:
history.txt
从下载文件https://www.7-zip.org/history.txt
,这是一个永久的URL
/link
,因此请使用它...
"%__APPDIR__%bitsadmin.exe" /rawreturn /transfer 7-Zip-History "https://www.7-zip.org/history.txt" "%temp%\history.txt"
- 使用
for
循环从文件中获取变量中的当前版本history.txt
;使用过滤器,您的字符串将是第一个匹配项:
19.00
- 使用最后一个操作将文件名与下载连接起来,删除字符串中的
7z link
句点(19 00)来设置文件名和变量:.
!_7z_x32!
!_7z_x64!
set "_7z_x32=7z%%~i" & set "_7z_x64=7z%%~i-x64"
- 现在,我们可以将下载链接变量设置为 7-Zip 文件的当前/最新版本,方法是连接名称并
!_URL!
使用变量中的子字符串下载文件 7-Zip,将其!_url!
替换为空(删除/不显示)并在链接末尾.
添加.exe
/ :-x64.exe
!_URL!
rem :: if "!_os!" == "x32" the link URL will be set "_URL=https://www.7-zip.org/a/!_7z_x32:.=!.exe!"
rem :: if "!_os!" == "x64" the link URL will be set "_URL=https://www.7-zip.org/a/!_7z_x64:.=!-x64.exe!"
set "_URL=https://www.7-zip.org/a/!_7z_%_os%:.=!.exe"
@echo off && setlocal enabledelayedexpansion
set "_key=HKLM\Hardware\Description\System\CentralProcessor\0" & title <nul & color 0A & "%__APPDIR__%mode.com" 77,8
title 7-Zip Download/Install & "%__APPDIR__%Reg.exe" Query "!_key!"|find/i "x86">nul && set "_os=x64"||set "_os=x32"
"%__APPDIR__%bitsadmin.exe" /rawreturn /transfer 7-Zip-History "https://www.7-zip.org/history.txt" "%temp%\history.txt" && for /f %%i in ('
type "%temp%\history.txt"^|"%__APPDIR__%findstr.exe" /b .[0-9\.0-9].^|"%__APPDIR__%findstr.exe" /vi "Alpha Beta"')do set "_7z_v=%%i" && (
set "_7z_x32=7z%%~i" && set "_7z_x64=7z%%~i-x64" && set "_URL=https://www.7-zip.org/a/!_7z_%_os%:.=!.exe" && goto :Download:) || goto :EOF
:Download:
"%__APPDIR__%bitsadmin.exe" /NoWrap /Transfer "7-Zip v!_7z_v! !_os!Bit" /Download /Priority Foreground "!_URL!" "%tmp%\!_7z_%_os%:.=!.exe"
:Silent Install:
start "7-Zip v.!_7z_v! !_os!Bit" /wait "%tmp%\!_7z_%_os%:.=!.exe" /S
:Temp Temizle:
2>&1>nul del /q /F "%tmp%\!_7z_%_os%:.=!.exe" "%tmp%\history.txt"
:Right click group ve CRC SHA remove:
for %%i in ("MenuIcons 1","ContextMenu 16247")do for /f tokens^=1-2 %%I in ('echo/%%~i
')do "%__APPDIR__%Reg.exe" add "HKCU\Software\7-Zip\Options" /v "%%I" /t REG_DWORD /d "%%J" /f
:END:
"%__APPDIR__%TIMEOUT.exe" 5 & endlocal & goto :EOF
答案2
大文件时会出现 bitsadmin 问题。我使用 aria2 时遇到过这种情况。
@ECHO OFF
TITLE aria2
===============================================================================================================================================================================================
REG.EXE QUERY "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && SET OS=32BIT || SET OS=64BIT
IF NOT EXIST "%TEMP%\aria2c.exe" IF %OS%==32BIT POWERSHELL -Command "(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/l0k5gvygl53pzkg/aria2c.exe?dl=1', '%TEMP%\aria2c.exe')"
IF NOT EXIST "%TEMP%\aria2c.exe" IF %OS%==64BIT POWERSHELL -Command "(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/vh6lew82qm4ud9i/aria2c.exe?dl=1', '%TEMP%\aria2c.exe')"
===============================================================================================================================================================================================
TITLE 7-Zip
@ECHO ON
:: İndir
IF %OS%==32BIT %TEMP%\aria2c.exe -x16 -s16 -k1M -d%TEMP% --auto-file-renaming=false "https://www.7-zip.org/a/7z1900.exe" -o 7z.exe
IF %OS%==64BIT %TEMP%\aria2c.exe -x16 -s16 -k1M -d%TEMP% --auto-file-renaming=false "https://www.7-zip.org/a/7z1900-x64.exe" -o 7z.exe
:: Kur
START /wait %TEMP%\7z.exe /S
:: Sağtık gruplansın ve CRC SHA kaldır
Reg.exe add "HKCU\Software\7-Zip\Options" /v "MenuIcons" /t REG_DWORD /d "1" /f
Reg.exe add "HKCU\Software\7-Zip\Options" /v "ContextMenu" /t REG_DWORD /d "16247" /f
:: Kapat
TIMEOUT /T 5
EXIT