创建bat文件来下载程序但我找不到问题

说网址错误,但对我来说似乎是正确的。我正在尝试从互联网下载文件启动该程序,然后在该过程结束后删除该程序。任何帮助都会很棒

过程将是

启动exe ---> 创建简单的下载器 ---> 通过bat文件添加参数 ---> 启动文件 ---> 等待进程结束 ---> 删除下载的文件。我还没有添加等待进程和删除命令

@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  "https://download.splashtop.com/sos/SplashtopSOS.exe" sos.exe

sos.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);

}


子衿沉夜
浏览 98回答 1
1回答

泛舟湖上清波郎朗

我想我为你找到了一些东西,我为你做了一些调整。快乐的脚本编写!&nbsp;@echo off&nbsp;IF EXIST sos.exe goto delete&nbsp;&nbsp;IF NOT EXIST sos.exe goto skip&nbsp;:delete&nbsp;echo delete&nbsp;del /f sos.exe&nbsp;&nbsp;timeout 5&nbsp;:skip&nbsp;echo skip&nbsp;rem :: the first argument is the script name as it will be used for proper help message&nbsp;cscript //E:JScript //nologo "%~f0" "%~nx0" %*&nbsp;start sos.exe&nbsp;exit /b %errorlevel%&nbsp;&nbsp;&nbsp;@if (@X)==(@Y) @end JScript comment */// global variables and constantsvar ARGS = WScript.Arguments;var scriptName=ARGS.Item(0);var url="";var saveTo="";var user=0;var pass=0;var proxy=0;var bypass="";var proxy_user=0;var proxy_pass=0;var certificate=0;var force=true;//ActiveX objects//Use the right version of MSXML/*var progIDs = [ 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.5.0', 'Msxml2.DOMDocument.4.0', 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ]for (var i = 0; i < progIDs.length; i++) {&nbsp;try {&nbsp; &nbsp; &nbsp;var XMLHTTPObj = new ActiveXObject(progIDs[i]);&nbsp;}catch (ex) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}}if typeof&nbsp; XMLHTTPObj === 'undefined'{&nbsp;WScript.Echo ("You are using too ancient windows or you have no installed IE");&nbsp;WScript.Quit(1);}*/var XMLHTTPObj = new ActiveXObject("MSXML2.XMLHTTP");var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");var AdoDBObj = new ActiveXObject("ADODB.Stream");function existsItem(path){&nbsp;return FileSystemObj.FolderExists(path)||FileSystemObj.FileExists(path);}stripTrailingSlash = function(path){&nbsp;while (path.substr(path.length - 1,path.length) == '\\') {&nbsp; &nbsp; &nbsp;path=path.substr(0, path.length - 1);&nbsp;}&nbsp;return path;}function deleteItem(path){&nbsp;if (FileSystemObj.FileExists(path)){&nbsp; &nbsp; &nbsp;FileSystemObj.DeleteFile(path);&nbsp; &nbsp; &nbsp;return true;&nbsp;} else if (FileSystemObj.FolderExists(path) ) {&nbsp; &nbsp; &nbsp;FileSystemObj.DeleteFolder(stripTrailingSlash(path));&nbsp; &nbsp; &nbsp;return true;&nbsp;} else {&nbsp; &nbsp; &nbsp;return false;&nbsp;}}function writeFile(fileName,data ){&nbsp;AdoDBObj.Type = 1;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;AdoDBObj.Open();&nbsp;AdoDBObj.Position=0;&nbsp;AdoDBObj.Write(data);&nbsp;AdoDBObj.SaveToFile(fileName,2);&nbsp;AdoDBObj.Close();&nbsp; &nbsp;}function download( url,file){&nbsp;if (force && existsItem(file)){&nbsp; &nbsp; &nbsp;if(!deleteItem(file)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Unable to delete "+ file);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Quit(8);&nbsp; &nbsp; &nbsp;}&nbsp;}else if (existsItem(file)){&nbsp; &nbsp; &nbsp;WScript.Echo("Item " + file + " already exist");&nbsp; &nbsp; &nbsp;WScript.Quit(9);&nbsp;}&nbsp;&nbsp;&nbsp;if (proxy!=0 && bypass !="") {&nbsp; &nbsp; &nbsp;//https://msdn.microsoft.com/en-us/library/ms760236(v=vs.85).aspx&nbsp; &nbsp; &nbsp;XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,bypass);&nbsp;} else if (proxy!=0) {&nbsp; &nbsp; &nbsp;XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,"");&nbsp;}&nbsp;&nbsp;&nbsp;if (proxy_user!=0 && proxy_pass!=0 ) {&nbsp; &nbsp; &nbsp;//https://msdn.microsoft.com/en-us/library/ms763680(v=vs.85).aspx&nbsp; &nbsp; &nbsp;XMLHTTPObj.setProxyCredentials(proxy_user,proxy_pass);&nbsp;}&nbsp;&nbsp;if(certificate!=0) {&nbsp; &nbsp; &nbsp;//https://msdn.microsoft.com/en-us/library/ms763811(v=vs.85).aspx&nbsp; &nbsp; &nbsp;WinHTTPObj.setOption(3,certificate);&nbsp;}&nbsp;&nbsp;if (user!=0 && pass!=0){&nbsp; &nbsp; &nbsp;//https://msdn.microsoft.com/en-us/library/ms757849(v=vs.85).aspx&nbsp; &nbsp; &nbsp; XMLHTTPObj.Open('GET',url,false,user,pass);&nbsp;} else {&nbsp; &nbsp; &nbsp;XMLHTTPObj.Open('GET',url,false);&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;XMLHTTPObj.Send();&nbsp;var status=XMLHTTPObj.Status;&nbsp;&nbsp;switch(status){&nbsp; &nbsp; &nbsp;case 200:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Status: 200 OK");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;&nbsp; &nbsp; &nbsp;case 401:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Status: 401 Unauthorized");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Check if correct user and password were provided");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Quit(401);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;&nbsp; &nbsp; &nbsp;case 407:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Status:407 Proxy Authentication Required");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Check if correct proxy user and password were provided");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Quit(407);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;&nbsp; &nbsp; &nbsp;default:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Status: "+status);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo("Try to help yourself -> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Quit(status);&nbsp;}&nbsp;writeFile(file,XMLHTTPObj.ResponseBody);}function main(){&nbsp;url="https://download.splashtop.com/sos/SplashtopSOS.exe"&nbsp;saveTo="sos.exe";&nbsp;download(url,saveTo);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript