Recipe2.4.Installing or Uninstalling a Windows Component


Recipe 2.4. Installing or Uninstalling a Windows Component

Problem

You want to install or uninstall a Windows Component.

Solution

Using a graphical user interface

  1. From the Control Panel , open the Add or Remove Programs applet.

  2. Click on Add/Remove Windows Components.

  3. Click on the component you are interested in.

  4. If there are subcomponents, the Details button will become active. Click on it. Check the box beside the components you want to install. When you are done, click OK.

  5. Click Next. At this point the component(s) will be installed.

  6. Click Finish to close the screen.

Using a command-line interface

Create an answer file using a text editor, such as notepad.exe. Here is an example answer file that would install the DNS Server service:

[netoptionalcomponents] dns=1

See the Discussion section for more on answer files.

Next, run the sysocmgr utility with following parameters (assuming you named the answer file c:\comp_install.txt):

> sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\comp_install.txt

The sysocmgr utility has additional options for suppressing dialog boxes (/x and /q). For the complete list of sysocmgr options, run sysocmgr /? from a command line.


Using VBScript

Unfortunately, there are no scripting interfaces for installing Windows Components. However, you can run the sysocmgr command from the previous section directly within a batch script (.bat extension) or using the WScript.Shell Run method within VBScript.

' This code simulates the same steps from the command-line solution. ' First, an answer file is created containing the parameters to install ' the DNS Server. Then the sysocmgr command is invoked to perform the ' installation. strFile = "c:\comp_install.txt"     constForWriting = 2 set objFSO = CreateObject("Scripting.FileSystemObject") set objFile = objFSO.OpenTextFile(strFile, constForWriting, True) objFile.WriteLine("[netoptionalcomponents]") objFile.WriteLine("dns=1") objFile.Close     set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run("sysocmgr /i:%windir%\inf\sysoc.inf /u:" & _                         strFile, 0, TRUE) if intRC <> 0 then    WScript.Echo "Error returned from sysocmgr command: " & intRC else    WScript.Echo "Windows Component installed" end if

Discussion

A Windows Component is an optional feature of the operating system. A Windows Component can be anything from server service, such as DNS, to a small application, like Calculator. You've undoubtedly used the steps I described in the graphical solution to install a Windows Component before. Fewer people are as familiar with the command-line (and VBScript) solutions.

You can script the installation (and uninstallation for that matter) of Windows Components using the sysocmgr.exe utility. All you need is an answer file that contains the components to install or uninstall. This can in fact be the same answer file you use to do unattended installations. Sysocmgr.exe reads only the [Components] and [Netoptionalcomponents] sections of an answer file. To see all the available components you can include in these sections, you need to look at the unattended reference documentation that is available on the Windows Server CDs for Windows 2000 and Windows Server 2003.

On a Windows 2000 CD, navigate to \SUPPORT\TOOLS\ and open the deploy.cab file. Within deploy.cab is a file named unattend.doc, which you'll need to extract and open. This file contains all answer file settings. On a Windows Server 2003 CD, you also need to open \SUPPORT\TOOLS\deploy.cab, but instead you want to extract ref.chm from it. Within ref.chm is a section entitled Unattend.txt, which contains all of the settings.

Again, you'll want to look at the [Components] and [Netoptionalcomponents] sections of the reference documentation. For [Components] there are over 80 different entries you can use and for [Netoptionalcomponents] there are 13 possible entries. One difference to note about the two sections is that you enable or disable components in the [Components] section using on (to install) or off (to uninstall) and for the [Netoptionalcomponents] section you use 1 (to install) or 0 (to uninstall).

Here is a sample answer file that installs IIS and the DNS Server service:

[Components]  iis_common = on  iis_www = on  iis_www_vdir_scripts = on  iis_inetmgr = on  fp_extensions = on  iis_ftp = on  netoc = on     [NetOptionalComponents]          dns=1

Answer files are case insensitive, so DNS=1 is the same as dns=1.


See Also

MS KB 222444 (How to Add or Remove Windows Components with Sysocmgr.exe)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net