2016-05-23 5 views
1

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 

は常に失敗しますが、それはまた償却され、すぐにウィンドウから削除されます。私はタスクを完了するには、このスクリプトにadditonで何かをダウンロードするユーザーが必要としないネイティブのソリューションを探しています。

私が持っている2番目の問題は、現在のバージョンを取得する方法がないことです。ファイルは常にので、私は、サーバーやディレクトリを含むテキストファイルを印刷し、それをローカルに実行する方法の最新バージョンをテストするための方法が必要です

https://github.com/Khroki/MCEdit-Unified/releases/download/(version_number)/mcedit.(version_number).exe 

で保存されています。

+0

のwgetやカールなどのサードパーティ製のツールを使用せずに、純粋なバッチでファイルをダウンロードすることは不可能です。 – SomethingDark

+0

私はbitsadminを使用していますが、私のコマンドは何らかの理由で失敗します。理由は何ですか?私はまた、Windows 7-10で動作する限り、PowerShellを使用することにオープンしています – flanigomik

+1

いいえ、私はwgetを使用しています。私はBitsadminを働かせることは一度もありませんでした。 – SomethingDark

答えて

0

URLが正しいかどうかを確認してください。そうBitsadminを使用して、それが私のため5/5に動作します。この例:あなたがbitsadmin使用していない場合

@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 
::*************************************************************** 
関連する問題