batch-filevbscripthtahttpapplication

VBscript HTTP Status msgbox only pops up once issue


Here is the VBscript code inside a MS-HTA i am making, It's supposed to check for updates against a webserver every run.

But it isn't working, It does pop up once then if the user hits ok and doesn't download the new version, even if they remain on old version it never prompts again.

Any way i can make it prompt every run if the version is still outdated? Needs to be VBScript that can work inside a HTMLApplication MS-HTA.

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

Seems to be this line causing issues

Case 200, 202, 302 

Case 202 - Causes prompt every time by its self

Case 200, 202, 302 - causes it only once even if declined

Case 200 - does nothing by its self

200 – OK (standard successful http request)
202 – Accepted (request accepted for processing, but not completed)
302 – Found (via redirection)

As i said above, This code does work but only once. I would like it to work every time, I'm at a loss as to why i cant get it to work, Any ideas?

--- EDIT

I just went with batch as i know it better, and made this that works. it does depend on version 5 of powershell so wont work in windows 7, and a third party wget standalone exe but it works :)

: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

and telling it to run from the hta with

Sub  Window_onload

Const NORMAL_WINDOW = 1
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "VersionCheck.bat", "", , , NORMAL_WINDOW

End Sub

Solution

  • I just went with batch as i know it better, and made this that works. it does depend on version 5 of powershell so wont work in windows 7, and a third party wget standalone exe but it works :)

    :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
    

    and telling it to run from the hta with

    Sub  Window_onload
    
    Const NORMAL_WINDOW = 1
    Set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "VersionCheck.bat", "", , , NORMAL_WINDOW
    
    End Sub