Hello, here we go:

I'am trying to modify the MS03-39 script to install the MS03-032 script on
our pc's but I have problems:

Here is the MS-03-039 code:

<-------------------------------------------------------------------------->
' Patchinstall.vbs
' Patch installation script for MS03-026 and MS03-039
' (c) Microsoft 2003
' v1.03 cl
' cscript patchinstall.vbs Ipfile.txt LocalPathToPatches

on error resume next

const XP_Patch = "Patch_XP.exe"
const W2k_Patch = "Patch_W2k.exe"
const W2k3_Patch = "Patch_W2k3.exe"

If right(ucase(wscript.FullName),11)="WSCRIPT.EXE" then
wscript.echo "ERROR: You must run this script using cscript, for
example 'cscript " & wscript.scriptname & "'."
wscript.quit 0
end if

' USAGE
if wscript.arguments.count <> 2 then
wscript.echo "Usage: cscript " & wscript.scriptname & " <IpFile.txt>
<LocalPathToPatches>" & vbCrLf & vbCrLf & _
" <LocalPathToPatches> must be a full path of a folder that contains
all of these files:" & vbCrLf & _
" " & XP_Patch & vbCrLf & _
" " & W2k_Patch & vbCrLf & _
" " & W2k3_Patch
wscript.quit
end if

ipFile = wscript.arguments(0)
localPathToPatches = wscript.arguments(1)

set onet = createobject("wscript.network")
set ofs = createobject("scripting.filesystemobject")

' Verify that ipfile is accessible.
set oipFile = ofs.opentextfile(ipFile, 1, false)
if (Err.Number <> 0) then
wscript.echo "Cannot open " & ipFile
wscript.quit
end if

' Make sure to end with a \ character.
if right(localPathToPatches, 1) <> "\" then
localPathToPatches = localPathToPatches & "\"
end if

'Note that cim_datafile does not support UNC paths
'so everything must be handled through mapped drives.
if left(localPathToPatches, 2) = "\\" then
wscript.echo "<pathToExecutable> cannot be a UNC path, please map a
drive locally"
wscript.quit
end if

exeWinXP = ofs.getfile(localPathToPatches + XP_Patch).name
exeW2k = ofs.getfile(localPathToPatches + W2k_Patch).name
exeW2k3 = ofs.getfile(localPathToPatches + W2k3_Patch).name

' Verify that the patches are accessible.
if ((len(exeWinXP) = 0) OR (len(exeW2k) = 0) OR (len(exeW2k3) = 0)) then
wscript.echo "Cannot find patch files."
wscript.echo "Please verify that the <LocalPathToPatches> folder
contains all of these files:" & vbCrLf & _
" " & XP_Patch & vbCrLf & _
" " & W2k_Patch & vbCrLf & _
" " & W2k3_Patch
wscript.quit
end if


set osvcLocal = getobject("winmgmts:root\cimv2")

'The error-handling code is below the function that may throw one - execute
it.
on error resume next

while not oipFile.atEndOfStream
ip = oipFile.ReadLine()
wscript.echo vbCrLf & "Connecting to " & ip & "..."

Err.Clear
set osvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2")

if (Err.Number <> 0) then
wscript.echo "Failed to connect to " & ip & "."
else

exeCorrectPatch = detectOSPatch(osvcRemote)
if (exeCorrectPatch <> "") then
' Lay the bits on the remote computer.
wscript.echo "Installing patch " & exeCorrectPatch & "..."

onet.mapnetworkdrive "z:", "\\" & ip & "\C$"
set osourceFile = osvcLocal.get("cim_datafile=""" &
replace(localPathToPatches, "\", "\\") & exeCorrectPatch & """")
ret = osourceFile.Copy("z:\\Patchinst.exe")

if (ret <> 0 and ret <> 10) then
' Failure detected and failure was not "file already
exists."
wscript.echo "Failed copy to " & ip & " - error: " & ret
else
set oprocess = osvcRemote.Get("win32_process")

' Start the installation without user interaction, and
force a restart after completion.
ret = oprocess.create("c:\\Patchinst.exe -q -f")
if (ret <> 0) then
wscript.echo "Failed to start process on " & ip &
": " & ret
else
' Get a reference to the file that was copied.
set odestFile =
osvcLocal.get("cim_datafile=""z:\\Patchinst.exe""")

' Wait for the installation to complete.
for waitTime = 0 to 120 ' Lay and wait--up to
two minutes for the installation to complete.
wscript.Sleep 1000 ' Sleep one second.
' Delete temporary file as soon as possible
after it is freed.
if (odestFile.Delete() = 0) then
exit for
end if
next ' Otherwise, loop again and keep waiting...

wscript.echo "Installation successful."

end if 'Create process succeeded.
end if 'Copy succeeded.

onet.removenetworkdrive "z:", true
end if ' The script knows which patch to install.
end if ' Do the next IP address, then the next IP address...
wend

oipFile.close()

'Clean up, remove drive mapping (check this time, because it may not have
been mapped).
if ofs.folderexists("z:\") then
onet.removenetworkdrive "z:", true
end if

wscript.echo vbCrLf & "Patching complete. Exiting."

function detectOSPatch(osvcRemote)

set oOSInfo = osvcRemote.InstancesOf("Win32_OperatingSystem")
'Only one instance is ever returned (the currently active OS), even
though the following is a foreach.
for each objOperatingSystem in oOSInfo

if (objOperatingSystem.OSType <> 18) then
' Make sure that this computer is Windows NT-based.
wscript.echo ip & " is not a Windows XP, Windows 2000, or
Windows 2003 Server computer."
else
if (objOperatingSystem.Version = "5.0.2195") then
' Windows 2000 SP2, SP3, SP4.
if (objOperatingSystem.ServicePackMajorVersion = 2) or
(objOperatingSystem.ServicePackMajorVersion = 3) or
(objOperatingSystem.ServicePackMajorVersion = 4) then
systemType = exeW2k
end if

elseif (objOperatingSystem.Version = "5.1.2600") then
' Windows XP RTM, SP1.
if (objOperatingSystem.ServicePackMajorVersion = 0) or
(objOperatingSystem.ServicePackMajorVersion = 1) then
systemType = exeWinXP
end if

elseif (objOperatingSystem.Version = "5.2.3790") then
' Windows Server 2003 RTM
if (objOperatingSystem.ServicePackMajorVersion = 0) then
systemType = exeW2k3
end if
end if

if (systemType = "") then
'This was a Windows NT-based computer, but not with a
valid service pack.
wscript.echo "Could not patch " & ip & " - unhandled OS
version: " & objOperatingSystem.Caption & " SP" &
objOperatingSystem.ServicePackMajorVersion & "("& objOperatingSystem.Version
& ")"
end if
end if

next

detectOSPatch = systemType

end function
<---------------------------------------------------------------------------
--------->

Now I use the following code to detect the IE Version:
<---------------------------------------------------------------------------
>
RegPath = "HKLM\SOFTWARE\Microsoft\Internet Explorer\Version"

Set oShell = CreateObject("Wscript.Shell")
On Error Resume Next
sIEVer = oShell.RegRead(sRegPath)

If Err <> 0 Or sIEVer = "" Then
' IE version is 3.0 or less, set it to 0
sIEVer = "0.0.0.0"
End If
On Error Goto 0

aIEVer = Split(sIEVer, ".")
iMajorVersion = Cint(aIEVer(0))
iMinorVersion = Cint(aIEVer(1))
iBuildVersion = Cint(aIEVer(2))
iSubBuildVersion = Cint(aIEVer(3))

WScript.Echo "IE full version is : " & sIEVer
WScript.Echo "IE version is : " & iMajorVersion & "." & iMinorVersion
<---------------------------------------------------------------------------
---------------->
The two files work perfect seperate but how do I get them together so that
it detects the IE version instead of the OS and installs the right patch?

Thx
D.

Re: MS03-032 Install Script by Richard

Richard
Wed Sep 17 17:25:46 CDT 2003

Hi,

I like to use "Option Explicit" in my code to help troubleshooting. I also
only use "On Error Resume Next" when necessary, on statements where I plan
to trap expected errors. Then, I resume normal error handling with "On Error
GoTo 0". Both practices would have helped in this case, although I know I'm
criticizing a Microsoft script.

In any case, your snippet at the end works if you replace "RegPath" with
"sRegPath" when you assign the variable. You use sRegPath in the RegRead
method.

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
"Davy" <adeldax@yucom.be> wrote in message
news:OAqsuPVfDHA.460@TK2MSFTNGP12.phx.gbl...
> Hello, here we go:
>
> I'am trying to modify the MS03-39 script to install the MS03-032 script on
> our pc's but I have problems:
>
> Here is the MS-03-039 code:
>
>
<-------------------------------------------------------------------------->
> ' Patchinstall.vbs
> ' Patch installation script for MS03-026 and MS03-039
> ' (c) Microsoft 2003
> ' v1.03 cl
> ' cscript patchinstall.vbs Ipfile.txt LocalPathToPatches
>
> on error resume next
>
> const XP_Patch = "Patch_XP.exe"
> const W2k_Patch = "Patch_W2k.exe"
> const W2k3_Patch = "Patch_W2k3.exe"
>
> If right(ucase(wscript.FullName),11)="WSCRIPT.EXE" then
> wscript.echo "ERROR: You must run this script using cscript, for
> example 'cscript " & wscript.scriptname & "'."
> wscript.quit 0
> end if
>
> ' USAGE
> if wscript.arguments.count <> 2 then
> wscript.echo "Usage: cscript " & wscript.scriptname & " <IpFile.txt>
> <LocalPathToPatches>" & vbCrLf & vbCrLf & _
> " <LocalPathToPatches> must be a full path of a folder that contains
> all of these files:" & vbCrLf & _
> " " & XP_Patch & vbCrLf & _
> " " & W2k_Patch & vbCrLf & _
> " " & W2k3_Patch
> wscript.quit
> end if
>
> ipFile = wscript.arguments(0)
> localPathToPatches = wscript.arguments(1)
>
> set onet = createobject("wscript.network")
> set ofs = createobject("scripting.filesystemobject")
>
> ' Verify that ipfile is accessible.
> set oipFile = ofs.opentextfile(ipFile, 1, false)
> if (Err.Number <> 0) then
> wscript.echo "Cannot open " & ipFile
> wscript.quit
> end if
>
> ' Make sure to end with a \ character.
> if right(localPathToPatches, 1) <> "\" then
> localPathToPatches = localPathToPatches & "\"
> end if
>
> 'Note that cim_datafile does not support UNC paths
> 'so everything must be handled through mapped drives.
> if left(localPathToPatches, 2) = "\\" then
> wscript.echo "<pathToExecutable> cannot be a UNC path, please map a
> drive locally"
> wscript.quit
> end if
>
> exeWinXP = ofs.getfile(localPathToPatches + XP_Patch).name
> exeW2k = ofs.getfile(localPathToPatches + W2k_Patch).name
> exeW2k3 = ofs.getfile(localPathToPatches + W2k3_Patch).name
>
> ' Verify that the patches are accessible.
> if ((len(exeWinXP) = 0) OR (len(exeW2k) = 0) OR (len(exeW2k3) = 0)) then
> wscript.echo "Cannot find patch files."
> wscript.echo "Please verify that the <LocalPathToPatches> folder
> contains all of these files:" & vbCrLf & _
> " " & XP_Patch & vbCrLf & _
> " " & W2k_Patch & vbCrLf & _
> " " & W2k3_Patch
> wscript.quit
> end if
>
>
> set osvcLocal = getobject("winmgmts:root\cimv2")
>
> 'The error-handling code is below the function that may throw one -
execute
> it.
> on error resume next
>
> while not oipFile.atEndOfStream
> ip = oipFile.ReadLine()
> wscript.echo vbCrLf & "Connecting to " & ip & "..."
>
> Err.Clear
> set osvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2")
>
> if (Err.Number <> 0) then
> wscript.echo "Failed to connect to " & ip & "."
> else
>
> exeCorrectPatch = detectOSPatch(osvcRemote)
> if (exeCorrectPatch <> "") then
> ' Lay the bits on the remote computer.
> wscript.echo "Installing patch " & exeCorrectPatch & "..."
>
> onet.mapnetworkdrive "z:", "\\" & ip & "\C$"
> set osourceFile = osvcLocal.get("cim_datafile=""" &
> replace(localPathToPatches, "\", "\\") & exeCorrectPatch & """")
> ret = osourceFile.Copy("z:\\Patchinst.exe")
>
> if (ret <> 0 and ret <> 10) then
> ' Failure detected and failure was not "file already
> exists."
> wscript.echo "Failed copy to " & ip & " - error: " &
ret
> else
> set oprocess = osvcRemote.Get("win32_process")
>
> ' Start the installation without user interaction, and
> force a restart after completion.
> ret = oprocess.create("c:\\Patchinst.exe -q -f")
> if (ret <> 0) then
> wscript.echo "Failed to start process on " & ip &
> ": " & ret
> else
> ' Get a reference to the file that was copied.
> set odestFile =
> osvcLocal.get("cim_datafile=""z:\\Patchinst.exe""")
>
> ' Wait for the installation to complete.
> for waitTime = 0 to 120 ' Lay and wait--up to
> two minutes for the installation to complete.
> wscript.Sleep 1000 ' Sleep one second.
> ' Delete temporary file as soon as possible
> after it is freed.
> if (odestFile.Delete() = 0) then
> exit for
> end if
> next ' Otherwise, loop again and keep waiting...
>
> wscript.echo "Installation successful."
>
> end if 'Create process succeeded.
> end if 'Copy succeeded.
>
> onet.removenetworkdrive "z:", true
> end if ' The script knows which patch to install.
> end if ' Do the next IP address, then the next IP address...
> wend
>
> oipFile.close()
>
> 'Clean up, remove drive mapping (check this time, because it may not have
> been mapped).
> if ofs.folderexists("z:\") then
> onet.removenetworkdrive "z:", true
> end if
>
> wscript.echo vbCrLf & "Patching complete. Exiting."
>
> function detectOSPatch(osvcRemote)
>
> set oOSInfo = osvcRemote.InstancesOf("Win32_OperatingSystem")
> 'Only one instance is ever returned (the currently active OS), even
> though the following is a foreach.
> for each objOperatingSystem in oOSInfo
>
> if (objOperatingSystem.OSType <> 18) then
> ' Make sure that this computer is Windows NT-based.
> wscript.echo ip & " is not a Windows XP, Windows 2000, or
> Windows 2003 Server computer."
> else
> if (objOperatingSystem.Version = "5.0.2195") then
> ' Windows 2000 SP2, SP3, SP4.
> if (objOperatingSystem.ServicePackMajorVersion = 2) or
> (objOperatingSystem.ServicePackMajorVersion = 3) or
> (objOperatingSystem.ServicePackMajorVersion = 4) then
> systemType = exeW2k
> end if
>
> elseif (objOperatingSystem.Version = "5.1.2600") then
> ' Windows XP RTM, SP1.
> if (objOperatingSystem.ServicePackMajorVersion = 0) or
> (objOperatingSystem.ServicePackMajorVersion = 1) then
> systemType = exeWinXP
> end if
>
> elseif (objOperatingSystem.Version = "5.2.3790") then
> ' Windows Server 2003 RTM
> if (objOperatingSystem.ServicePackMajorVersion = 0)
then
> systemType = exeW2k3
> end if
> end if
>
> if (systemType = "") then
> 'This was a Windows NT-based computer, but not with a

> valid service pack.
> wscript.echo "Could not patch " & ip & " - unhandled
OS
> version: " & objOperatingSystem.Caption & " SP" &
> objOperatingSystem.ServicePackMajorVersion & "("&
objOperatingSystem.Version
> & ")"
> end if
> end if
>
> next
>
> detectOSPatch = systemType
>
> end function
>
<---------------------------------------------------------------------------
> --------->
>
> Now I use the following code to detect the IE Version:
>
<---------------------------------------------------------------------------
> >
> RegPath = "HKLM\SOFTWARE\Microsoft\Internet Explorer\Version"
>
> Set oShell = CreateObject("Wscript.Shell")
> On Error Resume Next
> sIEVer = oShell.RegRead(sRegPath)
>
> If Err <> 0 Or sIEVer = "" Then
> ' IE version is 3.0 or less, set it to 0
> sIEVer = "0.0.0.0"
> End If
> On Error Goto 0
>
> aIEVer = Split(sIEVer, ".")
> iMajorVersion = Cint(aIEVer(0))
> iMinorVersion = Cint(aIEVer(1))
> iBuildVersion = Cint(aIEVer(2))
> iSubBuildVersion = Cint(aIEVer(3))
>
> WScript.Echo "IE full version is : " & sIEVer
> WScript.Echo "IE version is : " & iMajorVersion & "." & iMinorVersion
>
<---------------------------------------------------------------------------
> ---------------->
> The two files work perfect seperate but how do I get them together so that
> it detects the IE version instead of the OS and installs the right patch?
>
> Thx
> D.
>
>