我正在尝试创build一个自动化脚本来安装和更新Windows工程编辑器MCEDIT。 这是我到目前为止
@echo off REM finds the architecture of the windows installation. reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set arc=32BIT || set arc=64BIT if %arc%==32BIT GOTO 32 if %arc%==64BIT GOTO 64 REM placeholder for testing. set version=1.5.3.0 :32 REM attepts to use bitsadmin to download file but fails. bitsadmin.exe /transfer "JobName" https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe .\install.exe :64 REM another attempt at bitsadmin that also fails bitsadmin.exe /transfer "test" /download https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.64bit.exe .\install.exe REM unzips the auto extractor to current location install.exe /s /d %cd% :end echo end pause
所以我遇到的第一个问题就是
bitsadmin.exe /transfer "JobName" https://github.com/Khroki/MCEdit-Unified/releases/download/^%version%/MCEdit.^%version%.Win.32bit.exe .\install.exe
总是失败,它也被贬值,很快就会从窗户中剔除。 我正在寻找一个本地的解决scheme,不需要用户下载任何东西来添加到这个脚本来完成任务。
我遇到的第二个问题是我没有办法得到当前的版本。 该文件始终存储在
https://github.com/Khroki/MCEdit-Unified/releases/download/(version_number)/mcedit.(version_number).exe
所以我需要一种方法来testing服务器上的最新版本,或者打印包含目录的文本文件并在本地执行的方法。
检查您的网址是否正确; 所以这是一个使用Bitsadmin
的例子,它为我工作5/5:
@echo off :menuLOOP cls Title Downloading Cleaning Tools to remove virus by Hackoo 2016 Color 9E & Mode con cols=80 lines=11 echo( echo( echo( ***************************** Menu ****************************** echo( for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do ( echo %%A %%B ) echo( echo( ***************************************************************** set choice= echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF echo( & call :menu_[%choice%] GOTO:menuLOOP ::*********************************************************** :menu_[1] Download and Scan with RogueKiller Removal Tool Cls Mode con cols=100 lines=5 & color 9E echo( Set "URL=http://www.sur-la-toile.com/RogueKiller/RogueKiller.exe" Set "Location=%userprofile%\Desktop\RogueKiller.exe Title Downloading RogueKiller Virus Removal Tool ... Call :Download "%URL%" "%Location%" Start "" "%Location%" Goto:MenuLoop ::************************************************************ :menu_[2] Download and Scan with McAfee Stinger Scanner Tool Cls Mode con cols=100 lines=5 & color 9E echo( Set "URL32=http://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger32.exe" Set "URL64=http://downloadcenter.mcafee.com/products/mcafee-avert/stinger/stinger64.exe" Set "Location=%userprofile%\Desktop\stinger32.exe Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0 REG Query %RegQry% > checkOS.txt Find /i "x86" < CheckOS.txt > StringCheck.txt If %ErrorLevel% EQU 0 ( Echo "This is 32 Bit Operating system" pause Title Downloading McAfee Stinger Scanner Tool ... Call :Download "%URL32%" "%Location%" Del checkOS.txt & del StringCheck.txt ) ELSE ( Set "Location=%userprofile%\Desktop\stinger64.exe Title Downloading McAfee Stinger Scanner Tool ... Echo "This is 64 Bit Operating System" pause Call :Download "%URL64%" "%Location%" Del checkOS.txt & del StringCheck.txt ) Goto:MenuLoop ::************************************************************** :Download <URL> <Location> Set URL="%~1" Set Location="%~2" If Exist "%~2" Del "%~2" Bitsadmin /transfer "Download" "%~1" "%~2" If Exist "%~2" Start "" "%~2" If %ErrorLevel% GTR 0 ( Call :PSDownload "%~1" "%~2" ) Goto:MenuLoop ::************************************************************** Rem Function in Powershell for Downloading file :PSDownload <url> <file> Set PSFile=%Tmp%\PSFile.ps1 ( echo $down = New-Object System.Net.WebClient; echo $url = "%~1"; echo $file = "%~2"; echo $down.DownloadFile($url,$file^); echo $exec = New-Object -com shell.application; echo $exec.shellexecute($file^); )>%PSFile% If Exist "%~2" Del "%~2" Call :Speak "Please Wait... Downloading file "%~2" is in Progress..." Powershell.exe -ExecutionPolicy bypass -file %PSFile% If Exist "%~2" Start "" "%~2" Del %PSFile% Goto:MenuLoop ::***************************************************************