创建一个bat文件来下载程序,我找不到问题
Posted
技术标签:
【中文标题】创建一个bat文件来下载程序,我找不到问题【英文标题】:Creating a bat file to download a program and I can't find the issue 【发布时间】:2021-03-28 07:10:11 【问题描述】:说网址是错误的,但对我来说似乎是正确的。 我正在尝试从 Internet 下载文件启动该程序,然后在该过程结束后删除该程序。 任何帮助都会很棒
过程将是
启动 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);
【问题讨论】:
你应该仍然使用:: simpledownloader.exe "%~1" "%~2"
,而不是:: simpledownloader.exe "%%~1" "%%~2
。我也不想通过http://
下载任何东西,而不是https://
。
最重要的是,我不确定您是否知道,但您似乎正在尝试将批处理文件用作混合 cmd/js 文件,但似乎没有将其与另一种方式是每个都被视为其各自解释器/引擎的正确语法。您使用了 ****** end of jscript comment ******/
,但没有包含任何定义 jscript 注释开头的内容,例如 @set @x=0 /*
或 @if (true == false) @end /*
。
您认为这可能是 tls 问题吗?我很绿,我将如何强制 tls 1.2
我认为主要问题是我告诉你的!您从混合 cmd/js 文件中复制了代码 sn-p,并省略了其中的一些。现在您已经添加了该代码,您可能会遇到不同的问题,但由于您没有提供任何调试信息,我无意只给您另一个要修复的东西,然后是另一个等等,直到您告诉我它一切如你所愿。这是一个技术网站,您应该明白,您在这个问题中的角色是为我们提供我们需要的一切,以便我们自己重现您的问题,“说 url 错误”是不够的。跨度>
@Compo 这只是一个糟糕的复制和粘贴,抱歉...我在上面修复了它。
【参考方案1】:
我想我为你找到了一些东西,我为你做了一些调整。 快乐的脚本!
@echo off
IF EXIST sos.exe goto delete
IF NOT EXIST sos.exe goto skip
:delete
echo delete
del /f sos.exe
timeout 5
:skip
echo skip
rem :: the first argument is the script name as it will be used for proper help message
cscript //E:JScript //nologo "%~f0" "%~nx0" %*
start sos.exe
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
// global variables and constants
var 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++)
try
var XMLHTTPObj = new ActiveXObject(progIDs[i]);
catch (ex)
if typeof XMLHTTPObj === 'undefined'
WScript.Echo ("You are using too ancient windows or you have no installed IE");
WScript.Quit(1);
*/
var XMLHTTPObj = new ActiveXObject("MSXML2.XMLHTTP");
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
var AdoDBObj = new ActiveXObject("ADODB.Stream");
function existsItem(path)
return FileSystemObj.FolderExists(path)||FileSystemObj.FileExists(path);
stripTrailingSlash = function(path)
while (path.substr(path.length - 1,path.length) == '\\')
path=path.substr(0, path.length - 1);
return path;
function deleteItem(path)
if (FileSystemObj.FileExists(path))
FileSystemObj.DeleteFile(path);
return true;
else if (FileSystemObj.FolderExists(path) )
FileSystemObj.DeleteFolder(stripTrailingSlash(path));
return true;
else
return false;
function writeFile(fileName,data )
AdoDBObj.Type = 1;
AdoDBObj.Open();
AdoDBObj.Position=0;
AdoDBObj.Write(data);
AdoDBObj.SaveToFile(fileName,2);
AdoDBObj.Close();
function download( url,file)
if (force && existsItem(file))
if(!deleteItem(file))
WScript.Echo("Unable to delete "+ file);
WScript.Quit(8);
else if (existsItem(file))
WScript.Echo("Item " + file + " already exist");
WScript.Quit(9);
if (proxy!=0 && bypass !="")
//https://msdn.microsoft.com/en-us/library/ms760236(v=vs.85).aspx
XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,bypass);
else if (proxy!=0)
XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,"");
if (proxy_user!=0 && proxy_pass!=0 )
//https://msdn.microsoft.com/en-us/library/ms763680(v=vs.85).aspx
XMLHTTPObj.setProxyCredentials(proxy_user,proxy_pass);
if(certificate!=0)
//https://msdn.microsoft.com/en-us/library/ms763811(v=vs.85).aspx
WinHTTPObj.setOption(3,certificate);
if (user!=0 && pass!=0)
//https://msdn.microsoft.com/en-us/library/ms757849(v=vs.85).aspx
XMLHTTPObj.Open('GET',url,false,user,pass);
else
XMLHTTPObj.Open('GET',url,false);
XMLHTTPObj.Send();
var status=XMLHTTPObj.Status;
switch(status)
case 200:
WScript.Echo("Status: 200 OK");
break;
case 401:
WScript.Echo("Status: 401 Unauthorized");
WScript.Echo("Check if correct user and password were provided");
WScript.Quit(401);
break;
case 407:
WScript.Echo("Status:407 Proxy Authentication Required");
WScript.Echo("Check if correct proxy user and password were provided");
WScript.Quit(407);
break;
default:
WScript.Echo("Status: "+status);
WScript.Echo("Try to help yourself -> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes");
WScript.Quit(status);
writeFile(file,XMLHTTPObj.ResponseBody);
function main()
url="https://download.splashtop.com/sos/SplashtopSOS.exe"
saveTo="sos.exe";
download(url,saveTo);
【讨论】:
我会运行它,虽然 iexpress 将其设为 exe 以便于分发,但请确保将其列入白名单,一些防病毒程序会标记这一点。以上是关于创建一个bat文件来下载程序,我找不到问题的主要内容,如果未能解决你的问题,请参考以下文章