Ветеран
Сообщения: 27449
Благодарности: 8087
|
Профиль
|
Отправить PM
| Цитировать
PIL123, посмотрите на этот код:
читать дальше »
Код: 
Option Explicit
Dim strHotFixID
Dim strServicePackInEffect
Dim strPath2HotFix
Dim strPath2Log
Dim objDictionary
Dim objFSO
Dim strComputer
Dim objSWbemLocator
Dim objSWbemServicesEx
Dim collSWbemObjectSet
Dim objSWbemObjectEx
Dim strPrivilege
Dim strOSVersion
Dim strHotFixFullPath
strHotFixID = "File 1"
strServicePackInEffect = "KB943729"
strPath2HotFix = "C:\KB"
strPath2Log = "C:\Logs"
Set objDictionary = WScript.CreateObject("Scripting.Dictionary")
With objDictionary
.Add "Windows XP x86 ENU", "WindowsXP-KB943729-x86-ENU.exe"
.Add "Windows XP x86 RUS", "WindowsXP-KB943729-x86-RUS.exe"
.Add "Windows XP x64 ENU", "WindowsXP64-KB943729-x86-ENU.exe"
.Add "Windows XP x64 RUS" , "WindowsXP64-KB943729-x86-RUS.exe"
.Add "Windows Server 2003 x86 ENU", "WindowsServer2003-KB943729-x86-ENU.exe"
.Add "Windows Server 2003 x86 RUS", "WindowsServer2003-KB943729-x86-RUS.exe"
.Add "Windows Server 2003 x64 ENU", "WindowsServer2003-KB943729-x64-ENU.exe"
.Add "Windows Server 2003 x64 RUS", "WindowsServer2003-KB943729-x64-RUS.exe"
.Add "Windows Vista x86 ENU", "Windows6.0-KB943729-x86-ENU.msu"
.Add "Windows Vista x86 RUS", "Windows6.0-KB943729-x86-RUS.msu"
.Add "Windows Vista x64 ENU", "Windows6.0-KB943729-x64-ENU.msu"
.Add "Windows Vista x64 RUS", "Windows6.0-KB943729-x64-RUS.msu"
.Add "Windows Server 2008 x86 ENU", "Windows6.0-KB943729-x86-ENU.msu"
.Add "Windows Server 2008 x86 RUS", "Windows6.0-KB943729-x86-RUS.msu"
.Add "Windows Server 2008 x64 ENU", "Windows6.0-KB943729-x64-ENU.msu"
.Add "Windows Server 2008 x64 RUS", "Windows6.0-KB943729-x64-RUS.msu"
.Add "Windows 7 x86 ENU", "Windows6.1-KB943729-x86-ENU.msu"
.Add "Windows 7 x86 RUS", "Windows6.1-KB943729-x86-RUS.msu"
.Add "Windows 7 x64 ENU", "Windows6.1-KB943729-x64-ENU.msu"
.Add "Windows 7 x64 RUS", "Windows6.1-KB943729-x64-RUS.msu"
.Add "Windows Server 2008 R2 x64 ENU", "Windows6.1-KB943729-x64-ENU.msu"
.Add "Windows Server 2008 R2 x64 RUS", "Windows6.1-KB943729-x64-RUS.msu"
End With
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objSWbemLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServicesEx = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
For Each strPrivilege In Array("SeBackupPrivilege", "SeRestorePrivilege", "SeShutdownPrivilege", "SeSecurityPrivilege", "SeTakeOwnershipPrivilege")
objSWbemServicesEx.Security_.Privileges.AddAsString strPrivilege, True
Next
Set collSWbemObjectSet = objSWbemServicesEx.ExecQuery( _
"SELECT * FROM Win32_QuickFixEngineering WHERE HotFixID='" & strHotFixID & "' AND ServicePackInEffect = '" & strServicePackInEffect & "'")
If collSWbemObjectSet.Count = 0 Then
strOSVersion = GetStandardWindowsVersion(objSWbemServicesEx)
If objDictionary.Exists(strOSVersion) Then
strHotFixFullPath = objFSO.BuildPath(strPath2HotFix, objDictionary.Item(strOSVersion))
WScript.Echo """" & strHotFixFullPath & """" & _
" /passive /norestart /log:""" & strPath2Log & "\" & _
strHotFixID & "_" & strServicePackInEffect & " [" & _
WScript.CreateObject("WScript.Network").ComputerName & "].log"""
If objFSO.FileExists(strHotFixFullPath) Then
With objSWbemServicesEx.Get("Win32_Process")
If .Create("""" & strHotFixFullPath & """" & _
" /passive /norestart /log:""" & strPath2Log & "\" & _
strHotFixID & "_" & strServicePackInEffect & " [" & _
WScript.CreateObject("WScript.Network").ComputerName & "].log""") = 0 Then
' Success execute
Else
'Can't execute
End If
End With
Else
' File not found
End If
Else
' OS <--> HotFix link not found
End If
End If
Set collSWbemObjectSet = Nothing
Set objSWbemServicesEx = Nothing
Set objSWbemLocator = Nothing
objDictionary.RemoveAll
Set objDictionary = Nothing
WScript.Quit 0
'=============================================================================
'=============================================================================
Function GetStandardWindowsVersion(objSWbemServicesEx)
Dim objDictionary
Dim objSWbemObjectEx_Win32_OperatingSystem
Dim objSWbemObjectEx_Win32_ComputerSystem
Dim strOS
Set objDictionary = WScript.CreateObject("Scripting.Dictionary")
With objDictionary
.Add "32-bit", "x86"
.Add "64-bit", "x64"
.Add "X86-based PC", "x86"
.Add "X64-based PC", "x64"
End With
For Each objSWbemObjectEx_Win32_OperatingSystem In objSWbemServicesEx.InstancesOf("Win32_OperatingSystem")
With objSWbemObjectEx_Win32_OperatingSystem
Select Case .Version
'==========================================================================
Case "5.1.2600"
strOS = "Windows XP x86"
'==========================================================================
Case "5.2.3790"
Select Case .ProductType
Case 1
strOS = "Windows XP x64"
Case 2, 3
For Each objSWbemObjectEx_Win32_ComputerSystem In .InstancesOf("Win32_ComputerSystem")
strOS = "Windows Server 2003 " & objDictionary.Item(objSWbemObjectEx_Win32_OperatingSystem.SystemType)
Exit For
Next
End Select
'==========================================================================
Case "6.0.6000", "6.0.6001", "6.0.6002"
Select Case .ProductType
Case 1
strOS = "Windows Vista " & objDictionary.Item(.OSArchitecture)
Case 2, 3
strOS = "Windows Server 2008 " & objDictionary.Item(.OSArchitecture)
End Select
'==========================================================================
Case "6.1.7600", "6.1.7601"
Select Case objSWbemObjectEx.ProductType
Case 1
strOS = "Windows 7 " & objDictionary.Item(.OSArchitecture)
Case 2, 3
strOS = "Windows Server 2008 R2 " & objDictionary.Item(.OSArchitecture)
End Select
'==========================================================================
Case Else
' Other
End Select
Select Case .OSLanguage
Case 1033
strOS = strOS & " ENU"
Case 1049
strOS = strOS & " RUS"
Case Else
' Other
End Select
Exit For
End With
Next
objDictionary.RemoveAll
Set objDictionary = Nothing
WScript.Echo strOS
GetStandardWindowsVersion = strOS
End Function
'=============================================================================
Здесь мы в начале скрипта перечисляем (по-хорошему, надо сие перечисление выносить во внешний ini/xml-файл) файлы обновлений соответственно версий, платформ и языка ОС. Основной вопрос, как обычно — правильно ли сии составляющие определяются.
|