如何从网络下载.exe文件并使用某些脚本运行它? [英] How to download .exe file from web and run it with some script?

查看:147
本文介绍了如何从网络下载.exe文件并使用某些脚本运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一些脚本(可能是.bat/.vbs或其他内容),然后双击下载并打开文件.

I need to create some script (maybe .bat/.vbs or something else) that will download and open the file on double-click.

我该怎么做?

示例: 我双击文件(run.bat),然后转到链接: http://download.teamviewer.com/download/TeamViewer_Setup_en.exe 下载并安装此文件.

Example: I double-click on file (run.bat) and it goes to the link: http://download.teamviewer.com/download/TeamViewer_Setup_en.exe download and install this file.

我尝试过这样的事情:

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", "http://download.teamviewer.com/download/TeamViewer_Setup_en.exe", 0 
oXMLHTTP.Send
Set oADOStream = CreateObject("ADODB" & ".Stream")
oADOStream.Mode = 3
oADOStream.Type = 1
oADOStream.Open
oADOStream.Write oXMLHTTP.responseBody
oADOStream.SaveToFile "C:\TeamViewer_Setup_en.exe", 2 
dim path, WshShell
path = "C:\"
set WshShell = WScript.CreateObject("Wscript.Shell")
WshShell.Run path & "TeamViewer_Setup_en.exe", ,true

但这没用.

推荐答案

EDIT :

EDIT : How can I download a file with batch file without using any external tools?
More detailed answer of how files can be downloaded from internet in windows.

这里有两种方法.第一种使用bitsadmin.exe,第二种使用混合jscript.net/bat(应另存为.bat).根据我的测试,.net速度更快,但是创建了一个小的.exe文件第二个是纯"批处理脚本.

Here are two ways.The first uses bitsadmin.exe and the second hybrid jscript.net/bat (should be saved as .bat).The .net way is faster according to my tests , but creates a small .exe file that is called.And the second is a "pure" batch script.

  @echo off
    setlocal

    call :download "http://download.teamviewer.com/download/TeamViewer_Setup_en.exe" teamv.exe
    teamv.exe
    exit /b %errorlevel%
    :download

    if "%2" equ "" (
        call :help
        exit /b 5
    )

    if "%1" equ "" (
        call :help
        exit /b 6
    )
    set url=%~1
    set file=%~2
    rem ----
    if "%~3" NEQ "" (
        set /A timeout=%~3
    ) else (
        set timeout=5
    )

    bitsadmin /cancel download >nul
    bitsadmin /create /download download >nul 
    call bitsadmin /addfile download "%url%" "%CD%\%file%" >nul
    bitsadmin /resume download >nul 
    bitsadmin /setproxysettings download AUTODETECT >nul

    set /a attempts=0
    :repeat
    set /a attempts +=1
    if "%attempts%" EQU "10" (
        echo TIMED OUT
        endlocal
        exit /b 1
    )
    bitsadmin /info download /verbose | find  "STATE: ERROR"  >nul 2>&1 && endlocal &&  bitsadmin /cancel download && echo SOME KIND OF ERROR && exit /b 2
    bitsadmin /info download /verbose | find  "STATE: SUSPENDED" >nul 2>&1 && endlocal &&  bitsadmin /cancel download &&echo FILE WAS NOT ADDED && exit /b 3
    bitsadmin /info download /verbose | find  "STATE: TRANSIENT_ERROR" >nul 2>&1 && endlocal &&  bitsadmin /cancel download &&echo TRANSIENT ERROR && exit /b 4
    bitsadmin /info download /verbose | find  "STATE: TRANSFERRED" >nul 2>&1 && goto :finishing 

    w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:%timeout%  >nul 2>&1
    goto :repeat
    :finishing 
    bitsadmin /complete download >nul
    echo download finished
    endlocal
    goto :eof

    :help
    echo %~n0 url file [timeout]
    echo.
    echo  url - the source for download
    echo  file - file name in local directory where the file will be stored
    echo  timeout - number in seconds between each check if download is complete (attempts are 10)
    echo.
    goto :eof

OR

@if (@X)==(@Y) @end /****** jscript comment ******

@echo off
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal
if exist simpledownloader.exe goto :skip_compilation

set "frm=%SystemRoot%\Microsoft.NET\Framework\"
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop


call %jsc% /nologo /out:"simpledownloader.exe" "%~dpsfnx0"
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation

:: download the file


::
::::::::::
:: simpledownloader.exe "%%~1" "%%~2"

simpledownloader.exe  "http://download.teamviewer.com/download/TeamViewer_Setup_en.exe" teamv2.exe
teamv.exe

:: del /q simpledownloader.exe
::
::::::::
::

exit /b 0


****** end of jscript comment ******/

import System;
var arguments:String[] = Environment.GetCommandLineArgs();
var webClient:System.Net.WebClient = new System.Net.WebClient();
print("Downloading " + arguments[1] + " to " + arguments[2]);
try {
    webClient.DownloadFile(arguments[1], arguments[2]);
} catch (e) {

        Console.BackgroundColor = ConsoleColor.Green;
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("\n\nProblem with downloading " + arguments[1] + " to " + arguments[2] + "Check if the internet address is valid");
        Console.ResetColor();
        Environment.Exit(5);
}

这篇关于如何从网络下载.exe文件并使用某些脚本运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆