这是我正在制作的MS-HTA中的VBscript代码,应该在每次运行时检查对Web服务器的更新。
但是它不起作用,如果用户点击确定并且没有,它将弹出一次 下载新版本,即使它们仍然使用旧版本,也不会再次提示。
如果版本仍然过时,我可以通过任何方式提示每次运行? 需要是可以在HTMLApplication MS-HTA内运行的VBScript。
Dim varHTTP, varBinaryString, varFileName, varLink
set objShell = CreateObject("WScript.Shell")
Set varHTTP = CreateObject("Microsoft.XMLHTTP")
Set varBinaryString = CreateObject("Adodb.Stream")
varFileName = "YoutubeDLV2.zip"
varNewFileName = "YoutubeDLV3.zip"
varLink = "https://MyURL.com/YTDL/V2/" & varFileName
varNewLink = "https://MyURL.com/YTDL/V3/" & varNewFileName
varHTTP.Open "GET", varLink, False
varHTTP.Send
CheckFile()
Sub CheckFile()
Select Case Cint(varHTTP.status)
Case 200, 202, 302
'it exists
Exit Sub
Case Else
'does not exist
msgbox "Update Found! Go to:" & vbNewLine &
"https://MyURL.com/YTDL/" & vbNewLine & "And download latest version." &
vbNewLine & vbNewLine & "Currently Running Version." & vbNewLine + varLink &
vbNewLine & vbNewLine & "Newest Version:" & vbNewLine + varNewLink
End Select
End Sub
似乎是这条线引起了问题
Case 200, 202, 302
Case 202-每次由其自身引起提示
案例200、202、302-即使被拒绝也只会导致一次
情况200-自己不执行任何操作
200 – OK (standard successful http request)
202 – Accepted (request accepted for processing, but not completed)
302 – Found (via redirection)
正如我上面所说,此代码确实有效,但只能运行一次。我希望它每次都能正常工作,我迷茫的为什么我无法使其正常工作,有什么想法吗?
---编辑
我刚了解了批处理,并使其有效。它确实依赖于Powershell的版本5,因此无法在Windows 7和第三方wget独立exe上运行,但它可以正常工作:)
:main
cls
set version=2.0
set filename=YoutubeDLV3.zip
wget.exe --no-check-certificate https://mysite/YTDL/version.txt >nul
set /p nwstvrsn=<version.txt
set nwstvrsn=%nwstvrsn: =%
if %version% lss %nwstvrsn% goto newupdateavailable
if %version%==%nwstvrsn% goto noupdateavailable
goto main
:newupdateavailable
cls
echo.
echo Downloading Update...
echo.
wget.exe --no-check-certificate https://mysite/YTDL/V2/%filename% -O "%filename%"
ping localhost -n 2 >nul
PowerShell.exe Expand-Archive %filename% -DestinationPath %userprofile%\Downloads\
pause
exit
:noupdateavailable
cls
echo.
echo No Update Available
echo.
pause
exit
并告诉它从hta运行
Sub Window_onload
Const NORMAL_WINDOW = 1
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "VersionCheck.bat", "", , , NORMAL_WINDOW
End Sub
答案 0 :(得分:1)
我刚了解了批处理,并使其有效。它确实依赖于Powershell的版本5,因此无法在Windows 7和第三方wget独立exe上运行,但它可以正常工作:)
:main
cls
set version=2.0
set filename=YoutubeDLV3.zip
wget.exe --no-check-certificate https://mysite/YTDL/version.txt >nul
set /p nwstvrsn=<version.txt
set nwstvrsn=%nwstvrsn: =%
if %version% lss %nwstvrsn% goto newupdateavailable
if %version%==%nwstvrsn% goto noupdateavailable
goto main
:newupdateavailable
cls
echo.
echo Downloading Update...
echo.
wget.exe --no-check-certificate https://mysite/YTDL/V2/%filename% -O "%filename%"
ping localhost -n 2 >nul
PowerShell.exe Expand-Archive %filename% -DestinationPath %userprofile%\Downloads\
pause
exit
:noupdateavailable
cls
echo.
echo No Update Available
echo.
pause
exit
并告诉它从hta运行
Sub Window_onload
Const NORMAL_WINDOW = 1
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "VersionCheck.bat", "", , , NORMAL_WINDOW
End Sub