Re: scripting patch installation

From: Torgeir Bakken (MVP) (Torgeir.Bakken-spam_at_hydro.com)
Date: 01/19/04


Date: Mon, 19 Jan 2004 04:03:01 +0100

surferboy wrote:

> just a quick note. the installation works fine. but on the
> line where it reads the registry it errors if that reg
> doesn't exist. what i want is for it to just install the
> patch if that registry value is non existant.
> thanks again

Some general comments first. I would suggest you use the WScript.Shell's Run
method instead of WMIs' Win32_Process Create method to launch the exe with.
The example I showed you in a previous post had an error (a hasty copy/paste
one), instead of

   intReturnCode = objShell.strCmd(sCmd, 1, True)

it should have been

   intReturnCode = objShell.Run(strCmd, 1, True)

As long as you are not operating on remote computers, WMI is overkill to use
for this. WScript.Shell's Run method is more lightweight and better to use in
this case.

If you want a script that also can handle different OS version and Service pack
levels when installing the KB824146 (MS03-039) on a local computer, take a look
here:

http://groups.google.com/groups?selm=40083D36.5478C0A@hydro.com

> ' Blaster Patch
> ' install script for patch q824146
>
> location = WshShell.CurrentDirectory +"\blasterfix.exe -u -
> z"
> version = WshShell.RegRead
> ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows
> XP\SP2\KB824146\Type")

Ok, back to your issue. WshShell.RegRead will err if the value you try to read
does not exist, so you need to error handle it with "On Error Resume Next", and
then turn on the internal error handling again with "On Error Goto 0". Instead
of doing this error handling every time you need to do a registry read, it is
easier to make a function that handles this internally (se Function RegRead
below)

Also, your script line above (version = ...) isn't used for anything, so you
can remove it.

Below is an updated version of your script that uses the function RegRead to
read from registry. I also have changed it to test on another value in
registry, the one Microsoft recommends you should use to see if the KB824146 is
installed or not. I also have changed it to use the Run method and allow spaces
in the path to the exe file.

'--------------------8<----------------------
' Blaster Patch
' install script for patch q824146

Set WshShell = CreateObject("WScript.Shell")

location = WshShell.CurrentDirectory & "\blasterfix.exe"
params = " -u -z"

sRegValue = "HKLM\SOFTWARE\Microsoft\Windows NT\" _
                  & "CurrentVersion\HotFix\KB824146\Installe"

If RegRead(sRegValue) <> "1" Then
  ' Setting the 3rd parameter to True to make
  ' the script wait for the installation to finish
  WshShell.Run """" & location & """" & params, 1, True
End If

Function RegRead(sRegValue)
  Set oShell = CreateObject("WScript.Shell")
  On Error Resume Next
  RegRead = oShell.RegRead(sRegValue)
  ' If the value does not exist, error is raised
  If Err Then
    RegRead = ""
    Err.clear
  End If
  ' If a value is present but uninitialized the RegRead method
  ' returns the input value in Win2k.
  If VarType(RegRead) < vbArray Then
    If RegRead = sRegValue Then
      RegRead = ""
    End If
  End If
  On Error Goto 0
End Function
'--------------------8<----------------------

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Relevant Pages

  • Re: Software Install script
    ... Yes I would like to check the registry to determine whether or not the application was previously installed. ... admin rights to be able to install software in the logon script. ... RegRead = oShell.RegRead' If the value does not exist, ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.scripting)
  • Re: SMS Installer cannot create an NT Service
    ... If you want to post the script I could look over it real quick and see if I ... You can set permissions on registry keys and hives through something like ... I did a repackage of this install using SMS ...
    (microsoft.public.sms.installer)
  • Re: Add/Remove windows componets on multiple computers autmaticaly
    ... to add fax service without need to install it manually on each computer. ... or in a computer startup script. ... the Fax Service, it will test if the service is missing on the computer, and if it is, it will create the input file to sysocmgr.exe on the fly, and then run sysocmgr.exe. ... RegRead = oShell.RegRead' If the value does not exist, ...
    (microsoft.public.windowsxp.configuration_manage)
  • Re: remove special value in registry with VB script
    ... now she need to install new ... the registry, I spent 4 hours delete "arcexe82" from the ... did is find "arcexe82", hit F3, found it, deleted it. ... So can you help me create some VB script to delet this ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Newbie help needed with scripting permissions
    ... > the app needs access to a new folder it creates for itself on install ... > and uninstall the app. ... One option is to use a VBScript StartUp script configured in Group Policy. ... you could save the month/year in the registry ...
    (microsoft.public.windows.server.scripting)