Automatic update for Batch script !

Discussion in 'Scripting' started by Yasser Da Silva, Aug 28, 2015.

  1. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    Hello
    i am working on my batch script so hard
    [Script] Win 10 Toggle Tweaker (V1.6) -Official thread-

    but the problem is that a lot of people is still using V1.1 or V1.2
    so i want to make the batch file check for updates automatically
    i have this idea that i was using in VB.Net :
    make a variable and make it's value the version of the current file
    then create a TXT file that contain the newer version of the script and upload it
    now when the script starts it downloads the TXT file and compare it with the variable value inside the script
    if the Ver in the TXT file is newer the the Ver in the script
    the script opens a link

    any ideas how to do this in BAT
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. MrTweakFreak

    MrTweakFreak MDL Junior Member

    Jul 31, 2009
    92
    13
    0
    #2 MrTweakFreak, Aug 28, 2015
    Last edited: Aug 28, 2015
    Using batch.. well i once made a launcher script that had an integrated auto-updater, but it used an external program named cURL.exe that downloaded a temporary changelog file which included a version string that was compared to the existing changelog file.

    I used to check for file changes using the webserver's eTag, but it was a pain to filter out the unneeded garbage data came with the header (or i must've overlooked something to solve this).

    Anyway, the update(r)/checking code is very basic but in the end it notifies the user if (s)he wants to update to the latest version or not, including the ability to disable/reenable (toggle) update notifications using a seperate batch file.

    The complete (and working) launcher is still available for free and can be downloaded from http://web.minecraftnoob.com/

    Perhaps it is of some use to you ;-)
     
  3. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    unfortunately you used an external exe file
    i want it to be directly from the batch
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. MrTweakFreak

    MrTweakFreak MDL Junior Member

    Jul 31, 2009
    92
    13
    0
    As you probably know, batch is limited. But hey, people can do crazy cool stuff with it, so who knows what else may be possible ;-)
     
  5. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    Batch is so limited but it contain cool features like writing files and running them
    so maybe someone can find the code in VBS or powershell and execute it via CMD
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    I have a code to read a txt file and put it into a variable
    what i need now is a code to download a file from a direct link to a specific location !!!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Xadiaris

    Xadiaris MDL Novice

    Apr 23, 2008
    28
    9
    0
    #7 Xadiaris, Aug 28, 2015
    Last edited by a moderator: Apr 20, 2017
    Here you are.


    Code:
     On Error Resume Next
     Set File = WScript.CreateObject("Microsoft.XMLHTTP")
     File.Open "GET", "!!!!!!!!!!FILE URL TO GET!!!!!!!!", False
     'This is Firefox 41.0 headers
     File.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0"
     File.Send
     If err.number <> 0 then 
        line =""
        Line  = Line &  vbcrlf & "" 
        Line  = Line &  vbcrlf & "Error getting file" 
        Line  = Line &  vbcrlf & "==================" 
        Line  = Line &  vbcrlf & "" 
        Line  = Line &  vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
        Line  = Line &  vbcrlf & "Source " & err.source 
        Line  = Line &  vbcrlf & "" 
        Line  = Line &  vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
        Line  = Line &  vbcrlf &  File.getAllResponseHeaders
        wscript.echo Line
        Err.clear
        wscript.quit
     End If
    
    On Error Goto 0
    
     Set BS = CreateObject("ADODB.Stream")
     BS.type = 1
     BS.open
     BS.Write File.ResponseBody
     BS.SaveToFile "!!!!!!!!LOCATION AND FILENAME TO SAVE!!!!!!", 2
     
  8. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    #8 Yasser Da Silva, Aug 28, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    i wrote this code and it's working fine

    Code:
    @echo off
    set CurV=1.6
    echo strFileURL = "http://download1248.mediafire.com/zb2e40jv48eg/0f5sh5gynkwd5b8/ToggleTweakerV.txt" > TWV.vbs
    echo     strHDLocation = "C:\Users\yasse\Desktop\TWV.TXT" >> TWV.vbs
    echo     Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") >> TWV.vbs
    echo     objXMLHTTP.open "GET", strFileURL, false >> TWV.vbs
    echo objXMLHTTP.send() >> TWV.vbs
    echo If objXMLHTTP.Status = 200 Then >> TWV.vbs
    echo Set objADOStream = CreateObject("ADODB.Stream") >> TWV.vbs
    echo objADOStream.Open>> TWV.vbs
    echo objADOStream.Type = 1 >> TWV.vbs
    echo objADOStream.Write objXMLHTTP.ResponseBody >> TWV.vbs
    echo objADOStream.Position = 0    >> TWV.vbs
    echo Set objFSO = Createobject("Scripting.FileSystemObject") >> TWV.vbs
    echo If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation >> TWV.vbs
    echo Set objFSO = Nothing >> TWV.vbs
    echo objADOStream.SaveToFile strHDLocation >> TWV.vbs
    echo objADOStream.Close >> TWV.vbs
    echo Set objADOStream = Nothing >> TWV.vbs
    echo End if >> TWV.vbs
    echo Set objXMLHTTP = Nothing >> TWV.vbs
    cscript TWV.vbs >nul 2>&1
    del TWV.vbs
    
    SetLocal EnableDelayedExpansion
    set content=
    for /F "delims=" %%i in (C:\Users\yasse\Desktop\TWV.TXT) do set content=!content! %%i
    set NewV=%content%
    
    if %NewV% GTR %CurV% (Goto New)
    if %CurV% == %NewV% (Goto CUR)
    :New
    echo new version
    echo start link HERE
    goto Main
    :CUR
    goto Main
    
    EndLocal
    
    
    :Main
    echo Main script here
    pause
    

    but now i have a problem with Mediafire
    when i change the TXT file content the normal link doesn't change but the site change the direct link
    http://download1248.mediafire.com/zb2e40jv48eg/0f5sh5gynkwd5b8/ToggleTweakerV.txt

    any idea to solve this
    if not i will upload the TXT file to Dropbox and see if it's the same thing
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Xadiaris

    Xadiaris MDL Novice

    Apr 23, 2008
    28
    9
    0
    Dropbox is the solution ;)
     
  10. Xadiaris

    Xadiaris MDL Novice

    Apr 23, 2008
    28
    9
    0
    strHDLocation = "C:\Users\yasse\Desktop\TWV.TXT" fix path is correct?

    maybe replace with strHDLocation = %CD%\TWV.TXT
     
  11. Yasser Da Silva

    Yasser Da Silva MDL Addicted

    Mar 15, 2015
    523
    2,542
    30
    #11 Yasser Da Silva, Aug 28, 2015
    Last edited: Aug 28, 2015
    (OP)

    yes i will do that
    that code is just to test the general idea
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...