Под WSH:
Код:

Option Explicit
Dim objFSO
Dim objWshShell
Dim strWGetPath
Dim str7ZipPath
Dim strUrl
Dim strOriginalCharset
Dim strUrlFilePattern
Dim objHTMLDocument
Dim objHTMLAnchorElement
Dim strUrlFile
Dim boolFound
Dim strWorkFolder
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objWshShell = WScript.CreateObject("WScript.Shell")
strUrl = "http://www.pfrf.ru/index.php?chapter_id=4116&data_id=6075&do=view_single"
strOriginalCharset = "windows-1251"
strUrlFilePattern = "http://www\.pfrf\.ru/userdata/branches/ot_orenb/program/Setup_Spu_orb_[\d_]*\.zip"
strWGetPath = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%\GnuWin32\bin\wget.exe")
str7ZipPath = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%\7-Zip\7z.exe")
Set objHTMLDocument = GetDocumentFromURL(strUrl, strOriginalCharset)
With WScript.CreateObject("VBScript.RegExp")
.Global = False
.IgnoreCase = True
.Pattern = strUrlFilePattern
WScript.StdOut.Write "Searching in: " & strUrl & "..."
boolFound = False
For Each objHTMLAnchorElement In objHTMLDocument.links
If .Test(objHTMLAnchorElement.href) Then
strUrlFile = objHTMLAnchorElement.href
boolFound = True
Exit For
End If
Next
End With
If boolFound Then
WScript.StdOut.WriteLine " OK"
WScript.StdOut.Write "Downloading: " & strUrlFile & "..."
If objWshShell.Run( _
"""" & strWGetPath & """ " & _
"--progress=dot:binary --tries=10 --timestamping " & _
"--directory-prefix=""" & objWshShell.ExpandEnvironmentStrings("%Temp%") & """ " & _
"""" & strUrlFile & """", 1, True) = 0 Then
WScript.StdOut.WriteLine " OK"
WScript.StdOut.Write "Extracting: " & objFSO.GetFileName(strUrlFile) & "..."
strWorkFolder = GetTemporaryName()
If objWshShell.Run( _
"""" & str7ZipPath & """ " & _
" x -o""" & strWorkFolder & """ -aoa """ & _
objFSO.BuildPath(objWshShell.ExpandEnvironmentStrings("%Temp%"), objFSO.GetFileName(strUrlFile)) & """ ""*""", 1, True) = 0 Then
WScript.StdOut.WriteLine " OK"
WScript.StdOut.Write "Installing: " & "Setup_Spu_orb.exe" & "..."
If objWshShell.Run( _
"""" & objFSO.BuildPath(strWorkFolder, "Setup_Spu_orb.exe") & """ /S /R100", 1, True) = 0 Then
WScript.StdOut.WriteLine " OK"
Else
WScript.StdOut.WriteLine " Error"
End If
objFSO.DeleteFolder strWorkFolder, True
Else
WScript.StdOut.WriteLine " Error"
End If
Else
WScript.StdOut.WriteLine " Error"
End If
Else
WScript.StdOut.WriteLine " Error"
End If
Set objWshShell = Nothing
Set objFSO = Nothing
WScript.Quit 0
'=============================================================================
'=============================================================================
Function GetDocumentFromURL(strURL, strCharset)
Const adModeReadWrite = 3
Const adTypeBinary = 1
Const adTypeText = 2
Dim objHTMLDocument
Dim objHTMLBaseElement
Dim arrHtmlText
Dim strUrlDomain
Dim strContent
Set objHTMLDocument = WScript.CreateObject("HTMLFile")
With WScript.CreateObject("VBScript.RegExp")
.Pattern = "^(http://.*?/).*"
strUrlDomain = .Execute(strUrl).Item(0).SubMatches(0)
End With
With WScript.CreateObject("MSXML2.XMLHTTP")
.open "GET", strURL, False
.send
arrHtmlText = .responseBody
End With
With WScript.CreateObject("ADODB.Stream")
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write arrHtmlText
.Position = 0
.Type = adTypeText
.Charset = strCharset
strContent = Replace(.ReadText, "<head>", "<head><base href=""" & strUrlDomain & """>", 1, -1, vbTextCompare)
With WScript.CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = True
.Pattern = "(<script[^>]*)"
objHTMLDocument.open
objHTMLDocument.write .Replace(strContent, "<script type='text/plain'")
objHTMLDocument.close
End With
End With
Set GetDocumentFromURL = objHTMLDocument
Set objHTMLDocument = Nothing
End Function
'=============================================================================
'=============================================================================
' Серый форум / vbscript: генерация пути для временного файла или папки
' (http://forum.script-coding.com/viewtopic.php?id=1221)
'=============================================================================
Function GetTemporaryName()
Const TemporaryFolder = 2
Dim strTempName
With WScript.CreateObject("Scripting.FileSystemObject")
Do
strTempName = .BuildPath(.GetSpecialFolder(TemporaryFolder), .GetTempName)
Loop While .FileExists(strTempName) Or .FolderExists(strTempName)
End With
GetTemporaryName = strTempName
End Function
'=============================================================================
P.S. Проверки на то, что приложение уже может быть установлено или запущено, равно как и проверки установленной версии — здесь не делается.
Цитата sergo123:
З.Ы.Ы. Естественно для работы скрипта в папке существуют wget.exe \ unzip\ timeout.exe (мало ли на каких машинах будит запускаться) »
|
Тогда правьте пути в:
Код:

strWGetPath = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%\GnuWin32\bin\wget.exe")
str7ZipPath = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%\7-Zip\7z.exe")