Microsoft KB Archive/827227

= How to use a visual basic script to install the 824146 (MS03-039) or 823980 (MS03-026) security patch on remote host computers =

Article ID: 827227

Article Last Modified on 9/5/2007

-

APPLIES TO


 * Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)
 * Microsoft Windows Server 2003, Enterprise Edition
 * Microsoft Windows Server 2003, Standard Edition (32-bit x86)
 * Microsoft Windows Server 2003, Web Edition
 * Microsoft Windows XP Professional
 * Microsoft Windows XP Tablet PC Edition
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Server

-



SUMMARY
This article includes a sample Microsoft Visual Basic Scripting Edition script that is named Patchinstall.vbs. This script is an example of how a network administrator can use Windows Management Instrumentation (WMI) scripting to install the 824146 (MS03-039) or the 823980 (MS03-026) security patch on remote host computers that do not have the patch installed in a Microsoft Windows NT, Windows 2000, or Windows Server 2003 domain environment. The Patchinstall.vbs script takes a file that contains IP addresses as input and installs the 824146 (MS03-039) or the 823980 (MS03-026) security patch from a known location on the remote host computer (C:\Patchinst.exe). For additional information about the 824146 (MS03-039) security patch, click the following article number to view the article in the Microsoft Knowledge Base:

824146 MS03-039: Buffer overrun in RPCSS may allow code execution

For additional information about the 823980 security patch, click the following article number to view the article in the Microsoft Knowledge Base:

823980 MS03-026: Buffer overrun in RPC may allow code execution

For additional information about a tool that network administrators can use to scan their network for computers that do not have these security patches installed, click the following article number to view the article in the Microsoft Knowledge Base:

827363 How to use the KB 824146 scanning tool to identify host computers that do not have the 823980 (MS03-026) or 824146 (MS03-039) security patches installed

MORE INFORMATION
The Patchinstall.vbs script performs these tasks:
 * The script reads a list of IP addresses for the remote host computers where you want to install the 824146 or the 823980 security patch. The script obtains this list from an ASCII text file that contains a list of IP address (one IP address per line). For example, you can use the Vulnerable.txt log file from the KB824146 scanning tool for the   file.
 * The script obtains the first IP address from the list.
 * The script determines the Windows version on the destination computer.
 * The script maps drive Z on the script computer to C$ on the destination computer.
 * The script copies the correct version of the patch (for Windows XP, Windows 2000, or Windows Server 2003) to C:\Patchinst.exe on the destination computer (by using the drive Z mapping).
 * The script causes the patch to be installed, and then automatically restarts the destination computers without any user input or dialog boxes by using the -q -f switches (Unattended installation mode).
 * The script waits for the installation to complete.
 * The script tries to delete the C:\Patchinst.exe file on the destination computer.
 * The script removes the drive Z mapping.
 * The script processes the next IP address in the list.

Important Microsoft recommends that you modify this sample script for your network environment, and that you then test your script in a test environment before you use it in a production environment.

To use the Patchinstall.vbs script, paste the following script in a text file that is named Patchinstall.vbs. Then, run the Patchinstall.vbs script by using the following command line: 

cscript patchinstall.vbs  LocalPathToPatches

In this command,  is a text file that contains a list of IP addresses for the remote host computers where you want to install the 824146 or the 823980 security patch. is the full path of a folder that contains the 824146 or the 823980 security patch packages (renamed to Patch_XP.exe for Windows XP, Patch_W2k.exe for Windows 2000, and Patch_W2k3.exe for Windows Server 2003).

The Patchinstall.vbs Script
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. ' Patchinstall.vbs ' Patch installation script for MS03-026 and MS03-039 ' (c) Microsoft 2003 ' v1.03 cl

on error resume next

const XP_Patch = &quot;Patch_XP.exe&quot; const W2k_Patch = &quot;Patch_W2k.exe&quot; const W2k3_Patch = &quot;Patch_W2k3.exe&quot;

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

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

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

set onet = createobject(&quot;wscript.network&quot;) set ofs = createobject(&quot;scripting.filesystemobject&quot;)

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

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

'Note that cim_datafile does not support UNC paths 'so everything must be handled through mapped drives. if left(localPathToPatches, 2) = &quot;\\&quot; then wscript.echo &quot; cannot be a UNC path, please map a drive locally&quot; 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 &quot;Cannot find patch files.&quot; wscript.echo &quot;Please verify that the  folder contains all of these files:&quot; & vbCrLf & _ &quot;     &quot; & XP_Patch & vbCrLf & _ &quot;     &quot; & W2k_Patch & vbCrLf & _ &quot;     &quot; & W2k3_Patch wscript.quit end if

set osvcLocal = getobject(&quot;winmgmts:root\cimv2&quot;)

'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 & &quot;Connecting to &quot; & ip & &quot;...&quot;

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

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

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

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

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

' 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 &quot;Installation successful.&quot;

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

onet.removenetworkdrive &quot;z:&quot;, 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(&quot;z:\&quot;) then onet.removenetworkdrive &quot;z:&quot;, true end if

wscript.echo vbCrLf & &quot;Patching complete. Exiting.&quot;

function detectOSPatch(osvcRemote)

set oOSInfo = osvcRemote.InstancesOf(&quot;Win32_OperatingSystem&quot;) '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 & &quot; is not a Windows XP, Windows 2000, or Windows 2003 Server computer.&quot; else if (objOperatingSystem.Version = &quot;5.0.2195&quot;) 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 = &quot;5.1.2600&quot;) then ' Windows XP RTM, SP1. if (objOperatingSystem.ServicePackMajorVersion = 0) or (objOperatingSystem.ServicePackMajorVersion = 1) then systemType = exeWinXP end if

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

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

next

detectOSPatch = systemType

end function

Keywords: kbinfo KB827227

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.