surferboy said:
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/[email protected]
' 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<----------------------