Check The Os Version For Hotfix And Install

转载 2007年10月11日 01:56:00

This script will check the OS version, check the registry for a particular hotfix (in this case, KB824146) - if it's not there, the script will prompt with a 'policy window,' and an 'OK' button to then execute the MS hotfix from a predefined server path (there's no way to say 'cancel'). Our network is laid out with every remote site using the exact same network path for public patches, so the server was the only real variable (you can modify the path vars in the script itself). So, in our login scripts, I had set up a quick check to see if the host OS was windows NT based (see script for actual syntax). If it was, then I told it to run the VBS script ('ptchrpc.vbs servername') - The script has a server variable set inside of it, so if no arguments are given, it will default to whatever is set there. This is good for those who run it manually. It was also written so that you could easily modify it and replace the hotfix variable with any new 'critical updates' that MS releases. Be sure to check and recheck your registry keys for each OS, though! If you have many remote users, you may want to write some logic into this script to find throughput, or if the network interface is a modem, etc. Comments are welcome!


'~~Author~~. Rob Dunn
'~~Script_Type~~. vbscript
'~~Sub_Type~~. System Administration
'~~Keywords~~. login script, batch file, rpc fix, patch, windows 2000, xp
' Install RPC Hotfix VBS script (ptchrpc.vbs)
' For use in a login.bat file or by itself to install a hotfix for a user
' usage: [ptchrpc.vbs servername]

' Runs on NT/2K/XP systems - XP home does not process login scripts, so you
' would have to run either the vbs or patch manually on them.
' I used the following statements in our login.bat file:
'        if %OS%!==Windows_NT! Goto RPCPatch
'        Goto Begin
'        :RPCPatch
'        "//domaincontroller/netlogon/ptchrpc.vbs" server
'        :Begin
'        Rest of script goes here
' Windows NT systems _must_ have WMI 1.5 loaded in order for the script to
' process correctly (particularly the 'If objArgs.Count = 1' statement).
' I've noticed that you don't have to reboot after WMI is installed for
' the script to operate properly on NT.
' You can get WMI 1.5 for NT from:
' If servername is not specified, you can set sServerName to a particular value
' below the 'ElseIf objArgs.Count = 0 Then' statement.
' This script was written with the intent of being able to use it for any
' Hotfix released by Microsoft. Be sure to double-check the registry keys
' If you do re-use the code for a new hotfix.
' Technical notes on Hotfix KB824146 from (command switches, registry keys, etc.):

Dim WSHShell
Dim sComputerName, sServer, sPatchPath, sSwitches, sSwitchesNT
Dim sServerName, sHotfix
Dim Command, objArgs

'If any glitches, script will resume by telling you that there was a problem
On Error Resume Next

Set objArgs = WScript.Arguments
If objArgs.Count = 1 Then
    'take the name after the command as the server name argument to pull the
    'patch from
    sServerName = objArgs(0)
ElseIf objArgs.Count = 0 Then
    'if no arguments are given at the command line, then set the server name
    'here as a default
    sServerName = "server"
End If

Set WSHShell = WScript.CreateObject("WScript.Shell")

    'change MS Q number below to check for different hotfix installs
    sHotfix = "KB824146"
    'Get local computer name to figure OS version below
    sComputerName = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

    'share and path after servername in which the patch resides
    sPatchPath = "/patches/rpcpatch"
    'Patch command exe after path - we renamed ours to something a bit shorter
    sWin2k = "/rpcw2k0910.exe"
    sWinXp = "/rpcwxp0910.exe"
    sWinNTWrk = "/rpcwntwrk0910.exe"
    sWinNTsrv = "/rpcwntsrv0910.exe"
    'command line switches for the patch
    sSwitches = " /f /u"
    'switches for NT
    sSwitchesNT = " -f -m"
Set objWMIService = GetObject("winmgmts://" & sComputerName & "/root/cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
    'wscript.echo objItem.Caption
    OSVer = objitem.caption

If InStr(1, OSVer, "2000") > 0 Then 'search for win2k reg key
    bKey = WSHShell.RegRead("HKLM/SOFTWARE/Microsoft/Updates/Windows 2000/SP5/"_
    & sHotfix & "/Description")
    'Set the command line - format: "//server/share/path/hotfix.exe" /switches
    sCmd = Chr(34) & "//" & sServerName & sPatchPath & sWin2k & Chr(34) & sSwitches
ElseIf Instr(1, OSVer, "XP") >0 Then 'search for winXP reg key
    'if the OS is XP with SP1 installed, then run following
    bKey = WSHShell.RegRead("HKLM/SOFTWARE/Microsoft/Updates/Windows XP/SP2/"_
    & sHotfix & "/Description")
    If bKey = "" Then 'if XP system does NOT have SP1 installed yet
        bKey = WSHShell.RegRead("HKLM/SOFTWARE/Microsoft/Updates/Windows XP/"_
        & "SP1/" & sHotfix & "/Description")
    End If
    'Set the command line
    sCmd = chr(34) & "//" & sServerName & sPatchPath & sWinXP & Chr(34) & sSwitches
ElseIf Instr(1, OSVer, "NT") >0 Then 'search for NT40 reg key
    bKey = WSHShell.RegRead("HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion/"_
    & "Hotfix/" & sHotfix & "/Hotfix Description")
    If Instr(1, OSVer, "Workstation") >0 Then 'set command line NT4 workstation
        'set the command
        sCmd = chr(34) & " //" & sServerName & sPatchPath & sWinNTwrk & ""_
        & Chr(34) & sSwitchesNT
    'Only other option would be if OS is NT _Server_, then set command for server
        'set the command line
        sCmd = chr(34) & "//" & sServerName & sPatchPath & sWinNTsrv & ""_
        & Chr(34) & sSwitchesNT
    End If
End If

'if registry key does not exist (i.e. if it is not installed), then prompt
' user with 'OK' only dialog to begin installation of patch.
' NOTE - if file doesn't exist in the path specified by this dialog, the
' user will not see an error. The dialog will go away, and re-appear
' upon next logon. Code could be written to check for existence of file...
'Change below to suit your needs - window reports pathname at the
' bottom.
If bKey = "" Then
    MyVar = MsgBox ("Per X's IS policies, this PC requires critical security "_
    & "update " & sHotfix & " to " & "protect your data. The installation "_
    & "should take less than one minute, and your computer will reboot upon "_
    & "completion. Once the patch has successfully installed, you will not "_
    & "receive this message again." & VBCRLF & VBCRLF & "Please do not disturb"_
    & " the installation process." & VBCRLF & VBCRLF & "Press OK to install."_
    & VBCRLF & VBCRLF & "If you experience errors, contact Support at "_
    & " 815-555-1212." & VBCRLF & VBCRLF & "The update will be installed from "_
    & sCmd & ".", 48, "Critical " & OSVer & " Security Update - September "_
    & " 10th, 2003")


    'If key does exist, then do not run patch - remark out the following
    ' three lines if you don't want to be prompted after the patch
    ' is installed during successive logins.
    MsgBox "This system has the Microsoft security update " & sHotfix & ""_
    & " installed ", 64, "Critical " & OSVer & " Security Update - "_
    & "September 10th, 2003"
End If

Public Function RunPatch
    'set path of executable to command variable
    Command = sCmd
    'run the command
    WSHShell.Run Command,1,False
End Function 

查看Linux系统版本的方法 &&

首先介绍一下常用的查看Linux系统版本的几种方法 方法1 # lsb_release   -a LSB Version:    :core-4.1-amd64:core-4.1-n...
  • sunny05296
  • sunny05296
  • 2017年03月25日 22:28
  • 732


最近终于开始动xlua了 ,一开始官方的例子大都能运行,可到了Hotfix是就报错了,在群里问了下,结果 自己太马虎都没看项目的FAQ,被群里的大佬们讥讽了一波,好难过,所以记录下学习的过程 1、h...
  • sinat_23156865
  • sinat_23156865
  • 2017年05月03日 18:52
  • 1427

Hotfix Check

Hotfix Check Why need this?      在做NB专案的过程中,经验发现微软的hotfix有时真的很有效。有些bug,看了好长时间都没有进展,不经意间发现装上微软的hotfix...
  • hgf1011
  • hgf1011
  • 2009年04月20日 09:32
  • 1803

Check RedHat/HP-UX OS version

一、check RedHat OS version: 方法一: View redhat-release file [root@server ~]# cat /etc/redhat-release...
  • tlaff
  • tlaff
  • 2017年06月09日 17:29
  • 192


  • a1533588867
  • a1533588867
  • 2017年06月21日 14:55
  • 652


随着项目中动态链接库越来越多,我们也遇到了很多奇怪的问题,比如只在某一种 OS 上会出现的 `java.lang.UnsatisfiedLinkError`,但是明明我们动态库名称没错,ABI 也没错...
  • Tencent_Bugly
  • Tencent_Bugly
  • 2016年08月26日 15:48
  • 2494

The opatch minimum version check for patch failed

今天一个同事打补丁报错( , 补丁是160719。操作系统版本是redhat 7.1) 从表面看是opatch 版本低的原因,但是查看readme只需要.6以上的补丁就ok,不过...
  • huoshuyinhua
  • huoshuyinhua
  • 2016年08月19日 16:00
  • 1614

Mac笔记( 二) Mac OS X 10.10 安装与配置PhoneGap

Mac笔记( 三) Mac OS X 10.10 安装与配置PhoneGap  Darren 2014.11.23 Mac OS X 10.9.4 已经升级到了Mac OS X 1...
  • jiajiayaojiayou
  • jiajiayaojiayou
  • 2014年11月23日 18:00
  • 2749


  • qq_21688757
  • qq_21688757
  • 2017年03月02日 19:39
  • 2273

check the manual that corresponds to your MySQL server version for the right syntax错误

check the manual that corresponds to your MySQL server version for the right syntax to use near 'Ord...
  • hello__word__
  • hello__word__
  • 2017年07月29日 09:15
  • 13158
您举报文章:Check The Os Version For Hotfix And Install