Recipe 2.4. Installing or Uninstalling a Windows ComponentProblemYou want to install or uninstall a Windows Component. SolutionUsing a graphical user interface
Using a command-line interfaceCreate 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
Using VBScriptUnfortunately, 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 DiscussionA 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
See AlsoMS KB 222444 (How to Add or Remove Windows Components with Sysocmgr.exe) |