'CreateObject("Shell.Application").ShellExecute "http://www.cygwin.com/setup-x86_64.exe"
Dim Etag,ExeUrl
ExeUrl="http://www.cygwin.com/setup-x86_64.exe"
Set http=CreateObject("Msxml2.XMLHTTP")
http.open "GET",ExeUrl,false
http.send
Etag=http.getResponseHeader("Etag")
ConfigEtag=GetConfigEtag()
If Etag=ConfigEtag Then
Msgbox "setup-x86_64.exe 暂无可用更新....",64,"提示"
Else
confirmUpdate=Msgbox("有可用更新,是否现在更新?",vbyesno+vbquestion,"是否更新")
If confirmUpdate=7 Then Wscript.Quit
download ExeUrl,"setup-x86_64_newer.exe"
Msgbox "Download Complate!",64,"下载完成"
Call WriteEtag(Etag)
Call RenameFiles()
End IF
Function GetConfigEtag()
Set fso=Createobject("scripting.filesystemobject")
set file=fso.opentextfile("cygwin-setup-etag.txt",1)
configEtag=file.ReadLine()
file.close()
GetConfigEtag = configEtag
Set file = nothing
Set fso = nothing
End Function
Sub download(url,target)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim http,ado
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",url,False
http.send
Set ado = createobject("Adodb.Stream")
ado.Type = adTypeBinary
ado.Open
ado.Write http.responseBody
ado.SaveToFile target
ado.Close
End Sub
Sub WriteEtag(Etag)
Set fso=Createobject("scripting.filesystemobject")
set file=fso.opentextfile("cygwin-setup-etag.txt",2)
File.Write Etag
file.close()
End Sub
Sub RenameFiles()
Set fso=CreateObject("scripting.filesystemobject")
fso.MoveFile "setup-x86_64.exe","setup-x86_64_old.exe"
fso.MoveFile "setup-x86_64_newer.exe","setup-x86_64.exe"
Set fso = nothing
End Sub