1

Тема: HTA,VBS: Автообновление приложения и скриптов

Здравствуйте, есть приложение на .hta, появилась необходимость его обновления, чтобы не выкачивать весь клиент, а обновить только, сами скрипты.

Начал писать обработчик, проверку понятно как выполнить, но как выкачивать сам файл и заменить его...

<HTML>
<HEAD>
<TITLE>Update</TITLE>
<HTA:APPLICATION
    ID="HtaUpdate"
    VERSION="0.00"
    APPLICATIONNAME="HtaUpdate"
    SYSMENU="yes"
    MAXIMIZEBUTTON="yes"
    MINIMIZEBUTTON="yes"
    BORDER="thin"
    INNERBORDER="thin"
    SCROLL="auto"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="maximize"
>


<SCRIPT TYPE="text/vbscript" LANGUAGE="VBScript">

Option Explicit
Dim strAppId, strAppName, strAppVer
Const ROOT_URL  = "\\10.2.10.93\c$\2\" 'путь для загрузки
Const FILE_NAME = "version"				' имя файла
strAppId        = HtaUpdate.ID			' название файла - ID
strAppName      = HtaUpdate.ApplicationName 	'имя приложение в титле
strAppVer       = HtaUpdate.Version			'версия приложения - текущая


Sub Window_OnLoad()
    CheckForUpdates
    AppName.InnerHTML   = strAppName
    AppVersion.InnerHTML    = strAppVer
End Sub

Sub CheckForUpdates
	strCurrentVer = strAppVer 	' текущая версия = версии приложения
	strLatestVer  =  ' последняя версия = лежит на сервере

	If strLatestVer > strCurrentVer Then
	Update.InnerHTML = "<p> Вы используете версию (" & strCurrentVer _
                             & ") приложения - " & strAppName _
							 & ".<br/>Последняя версия приложения"    _
                             & strLatestVer & " доступа " _
                             & "<a href="" strfullurlwithoutextension="">здесь</a>.<p/><p/><p/>"
	end if
	
	If strLatestVer < strCurrentVer Then
            Update.InnerHTML = "<p>Вы используете последнию версию " & strCurrentVer _
                             & " приложения - " & strAppName "</p>"
        End If
end sub

</SCRIPT>

</SCRIPT>
</HEAD>
<BODY>
<DIV ALIGN="center">
<H1>Update</H1>
<P> </P>
<SPAN ID="Update"> </SPAN>
<P> </P>
</SPAN>
<P> </P>
<P id=footer>
<SPAN ID="AppName">Application Name</SPAN>, Version <SPAN ID="AppVersion"></SPAN>
</P>
</DIV>
</BODY>
</HTML>

2

Re: HTA,VBS: Автообновление приложения и скриптов

Покажу на примере VBS:

Path = "\\10.2.10.93\c$\2\"
CreateObject("Shell.Application").NameSpace(CreateObject("Scripting.FileSystemObject")._
GetParentFolderName(WScript.ScriptFullName)).CopyHere Path & WScript.ScriptName, 20

3

Re: HTA,VBS: Автообновление приложения и скриптов

Вот так отслеживает изменение, по текстовому файлу version в папке с программой, а ваш способ, можете поподробнее описать?, тоже сделать проверку подобную и в если текущая версия < версии на сервере, то начинается копирование?, не получилось запустить.

<HTML xmlns:IE>
<HEAD>
<TITLE>Update</TITLE>
<HTA:APPLICATION
    ID="Update"
    VERSION="2.11"
    APPLICATIONNAME="Update"
    SYSMENU="yes"
    MAXIMIZEBUTTON="yes"
    MINIMIZEBUTTON="yes"
    BORDER="thin"
    INNERBORDER="thin"
    SCROLL="auto"
    SINGLEINSTANCE="yes"
>

<SCRIPT TYPE="text/vbscript" LANGUAGE="VBScript">
Option Explicit
Dim strAppId, strAppName, strAppVer
Const ROOT_URL  = "\\10.2.10.93\c$\2\"
Const FILE_NAME = "version"
strAppId        = Update.ID
strAppName      = Update.ApplicationName
strAppVer       = Update.Version


Sub Window_OnLoad()
    CheckForUpdates
    AppName.InnerHTML   = strAppName
    AppVersion.InnerHTML    = strAppVer
End Sub

Sub CheckForUpdates()
    Dim strFullUrlWithoutExtension, strCurrentVer, strLatestVer,Path
    strFullUrlWithoutExtension = ROOT_URL & strAppId & "/" & FILE_NAME
    ' Change cursor to hourglass while checking for update
    Document.Body.Style.Cursor = "wait"
	strCurrentVer = strAppVer
    strLatestVer  = ParseTextFromHTML( strFullUrlWithoutExtension & ".txt")
    If Err.Number = 0 Then
        If strCurrentVer < strLatestVer then 
		 Update1.InnerHTML = "<p> You are using an invalid version (" & strCurrentVer _
                             & ") of the " & strAppName _
                             & ".<br/>The latest valid version is "    _
                             & strLatestVer & " and it is available " _
                             & "<a href="" strfullurlwithoutextension="">here</a>.<p/><p/><p/>"
	 else
     
            Update1.InnerHTML = "<p>You are using version " & strCurrentVer _
                             & " of the " & strAppName _
                             & ".<br/>An update to version " _
                             & strLatestVer & " is available " _
                             & "<a href="" strfullurlwithoutextension="">here</a>.</p><p/><p/><p/>"
        End If
    Else
        'error.
        Update1.InnerHTML = "<p>The version number could not be retrieved from:<br/>" & strFullUrlWithoutExtension & ".txt.</p><p/><p/><p/>"
        ' Release the object and return to default error handling
        On Error Goto 0
    End If
    ' Change cursor back to default
    Document.Body.Style.Cursor = "default"
End Sub


Function ParseTextFromHTML( ROOT_URL )
    Dim objIE
    ' Set the default value
    ParseTextFromHTML = ""
    ' Temporarily disable error handling
    On Error Resume Next
    ' Create an IE object
    Set objIE = CreateObject( "InternetExplorer.Application" )
    ' Load the requested URL
    objIE.Navigate ROOT_URL
    ' Wait for the requested URL to become available
    While objIE.Busy
    Wend
    ' Retrieve the body text
    ParseTextFromHTML = objIE.Document.Body.InnerText
    ' Release the object and return to default error handling
    On Error Goto 0
    objIE.Quit
    Set objIE = Nothing
End Function
</SCRIPT>
</HEAD>
<BODY>
<DIV ALIGN="center">
<H1>HTA Update Demo</H1>
<P> </P>
<SPAN ID="Update1"> </SPAN>
<P> </P>
</SPAN>
<P> </P>
<P id=footer>
<SPAN ID="AppName">Application Name</SPAN>, Version <SPAN ID="AppVersion">0.01</SPAN>,  © 2009
</P>
</DIV>
</BODY>
</HTML>

4

Re: HTA,VBS: Автообновление приложения и скриптов

Проще сравнивать по дате модификации:

SharePath = "\\10.2.10.93\c$\2\"
LocalPath = "C:\TestFolder\"
FileName  = "Test.hta"

Set Shell  = CreateObject("Shell.Application")
Set Folder = Shell.NameSpace(LocalPath)

If Shell.NameSpace(SharePath).ParseName(FileName).ModifyDate > Folder.ParseName(FileName).ModifyDate Then _
Folder.CopyHere SharePath & FileName, 20
Shell.Open(LocalPath & FileName)

5

Re: HTA,VBS: Автообновление приложения и скриптов

Создал две папки на диске С, local и server. Запускаю скрипт с следующим кодом, и начинают постоянно открываться окна программы.

<HTML>
<HEAD>
<TITLE>Update</TITLE>
<HTA:APPLICATION
    ID="HtaUpdate"
    VERSION="4.00" 'local
    APPLICATIONNAME="HtaUpdate"
    SYSMENU="yes"
    MAXIMIZEBUTTON="yes"
    MINIMIZEBUTTON="yes"
    BORDER="thin"
    INNERBORDER="thin"
    SCROLL="auto"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="maximize"
>

<SCRIPT TYPE="text/vbscript" LANGUAGE="VBScript">
	ServerPath = "C:\server\"
	LocalPath = "C:\local\"
	FileName  = "Test.hta"

Sub Window_OnLoad()
    CheckForUpdates
End Sub

Sub CheckForUpdates
		Set Shell  = CreateObject("Shell.Application")
		If Shell.NameSpace(ServerPath).ParseName(FileName).ModifyDate > Shell.NameSpace(LocalPath).ParseName(FileName).ModifyDate Then _
		Folder.CopyHere ServerPath & FileName, 20
		Shell.Open(LocalPath & FileName)
		Update.innerhtml = HtaUpdate.version
end sub

</script>
</script>
</head>
<body>
<div align="center">
<H1>Update</H1>
<P> </P>
<SPAN ID="Update"> HtaUpdate.version</SPAN>
<P> </P>
</SPAN>
<P> </P>
<P id=footer>
<span id="AppName">Application Name</SPAN>, Version <SPAN ID="AppVersion"></SPAN>
</p>
</div>
</body>
</html>

6

Re: HTA,VBS: Автообновление приложения и скриптов

Разумеется. Shell.Open я вставил для демонстрации. Вообще hta можно запускать прямо этим vbs, ничего не меняя в самом hta, если такой вариант устроит.