Click here to load reader

Windows Admin Scripting 03

  • View
    230

  • Download
    2

Embed Size (px)

Text of Windows Admin Scripting 03

Windows Admin Scripting Little Black Book3rd Edition

Chapter 3 Scripting Installations and UpdatesThis chapter is excerpted from Windows Admin Scripting Little Black Book, 3rd Edition, by Jesse M. Torres [ISBN: 1-933097-10-8]. Copyright (c) 2006, Paraglyph Press. Reprinted with permission. All rights reserved. To learn more about Paraglyph Press, please visit http://paraglyph.oreilly.com/.

Presented by

Chapter

3See page:46 46 47 47 48 48 49 50 50 51 51 51 52 52 53 53 55 55

Scripting Installations and UpdatesIf you need an immediate solution to:Scripting a Silent .NET Framework Installation Scripting a Silent MDACS Installation Scripting a Silent Windows 2000/XP Service Pack Installation Scripting an Internet Explorer Download Scripting a Silent Internet Explorer Install Scripting a Silent WinZip Installation Scripting a Silent RealVNC Installation Scripting a Silent Windows Media Player Installation Scripting a Silent DirectX Installation Working with the Windows Installer Scripting a Silent Acrobat Reader Install Scripting a QuickTime Install Scripting a Silent pcANYWHERE Installation Scripting a Silent Windows 2000 Resource Kit Installation Scripting the Windows Installer Installation Scripting Microsoft Office 2000/XP Disabling Windows Installer Rollbacks Installing the Windows Installer Clean Up Utility

39

Chapter 3 Scripting Installations and Updates

In BriefIn the previous chapter, you learned how to automate hard disk setups and images. Throughout this chapter, you will use various scripting methods to create unique scripting solutions to common administrative installations and updates. You will start by learning how to script installations from the command line. You will then learn how to use send keys to install windows and wizards using AutoIt.

3. Scripting Installations and Updates

Scripting MethodsNot all of us have the luxury of working with a centralized management system such as Systems Management Server (SMS) Lan Desk, or Tivoli. With new programs, program updates, service pack updates, and hot-fixes constantly coming out, installing all of these manually can consume most of an administrators day. Scripting provides a way to automate these tasks with little or no user intervention.

Microsoft Command-Line SwitchesMicrosoft installation and update executables support many different switches to allow for shell scripting and installation customization. Switches are not case-sensitive and, more often than not, they are not standardized. To make matters worse, Microsoft tends not to document some of the most useful switches (as you saw in Chapter 2). Here are some of the most common, and possibly undocumented, switches for Microsoft installation and update executables: /?Displays unhidden switches and usage /CExtracts files to folder specified with /T switch /C IDUsed to enter a 20-digit product ID /FForces applications to close at shutdown /K IDUsed to enter an 11-digit CD key /NDoes not back up files for uninstall /N nameUsed to enter a username for registration /N:VInstalls without version checking /OOverwrites OEM files without prompting /O organizationUsed to enter an organization name for registration 40

In Brief /QRuns in quiet mode, skips all prompts /Q:URuns in user quiet mode, shows some dialog boxes /Q:ARuns in admin quiet mode, shows no dialog boxes /RReinstalls the application /R:AAlways reboots /R:IReboots if necessary /R:NDoes not reboot, even if necessary

3. Scripting Installations and Updates

/R:SReboots without prompting /T:pathSpecifies or extracts files to a temporary working folder /URuns in unattended mode or uninstalls an application, prompts for shared file removal /UAUninstalls an application and shared files, without prompting /ZDoes not reboot when installation is complete

Windows and WizardsMany of the tasks of an administrator involve navigating through interactive windows and wizards. Whether installing a new program or adding a new piece of hardware, these wizards guide the user through a complicated setup process. This process involves scrolling through selections, clicking check boxes, selecting tabs, browsing, entering text, and more. Although these wizards are helpful, they frequently do not support scripting. In the past, administrators used macro recorders to deal with these unscriptable windows and wizards. The main problem with basic macro utilities is that they are great for performing linear tasks, but they choke when dealing with complex routines that require decisions. The solution is to use a send-keys utility, such as AutoIt.

Scripting Windows with AutoItAutoIt (www.autoitscript.com) is a free automation tool that can send key and mouse commands to Windows objects. AutoIt detects window titles and text and sends commands to specific windows based on that information. AutoIt reads commands stored in a textbased script file and performs the commands on a line-per-line basis. Although you can use other scripting send-keys methods, such as Windows Script Host (WSH) or KiXtart, AutoIt provides the easiest way to detect windows and send keys. 41

Chapter 3 Scripting Installations and Updates

Detecting Windows and TextSometimes multiple windows can have the same title. Luckily, AutoIt allows you to specify a combination of window title and window text to specify the exact window you want. Running the AutoIt Windows Information utility allows you to see the title, text, sizes, and mouse coordinates of the currently active window in real time. You can start this utility from the AutoIt start menu folder.

3. Scripting Installations and Updates

For example, suppose you wanted to script the Add New Hardware Wizard window (see Figure 3.1). Running the utility would show the window title and text (see Figure 3.2).

Adlibbing with AutoItOne of the advantages that AutoIt has over using other send-key methods, such as KiXtart or WSH, is the ability to immediately intercept windows that may occur unexpectedly. AutoIt refers to the ability to handle unexpected Windows as adlibbing. In order to use adlibbing, you must first enable it with the AdlibEnable command. When the script encounters any unforeseen error, window, and so on and adlibbing is enabled, the script can break out from its current location, execute the handle function you specified in the AdlibEnable command, and then return to the current location.

Figure 3.1 42

The Add New Hardware Wizard window.

In Brief

3. Scripting Installations and Updates

Figure 3.2

Detecting window title and text with /REVEAL.

Convert Script Files to EXEsIncluded in the AutoIt installation package is a utility called AUT2.EXE used to convert AutoIt script files into standalone executables. You can even password protect these executables from being turned back into AutoIt scripts. By converting your scripts, you can prevent users from reading your code and modifying your scripts. The conversion utility is menu-based and allows you to set your own executable icon, provided that it is 32 by 32 pixels in 16 colors.

Scripting AutoIt through COMYou can control AutoIt with KiXtart or Windows Script Host (or any language that can interact with COM) through AutoIts COM object called AutoItX3. To gain access to AutoItX3, you must first use the CreateObject function and set it to a variable:Set variable = CreateObject("AutoItX3.Control")

NOTE: For more information and details on usage, see the AutoItX3 control documentation included in the program install.

43

Chapter 3 Scripting Installations and Updates

Microsoft Windows InstallerBefore Windows 2000, installing and managing applications was a complete mess. Software companies created their own installation interfaces, each with its own set of rules, command-line options, and uninstall functions. This provided headaches for administrators who attempted to create common scripting solutions for application installations. To help reduce total cost of ownership (TCO) and provide a standardized set of installation rules, Microsoft created the Windows Installer.

3. Scripting Installations and Updates

The Windows Installer is a new installation and configuration service for 32-bit Windows platforms that standardizes the way programs install and uninstall. The Windows Installer is a Zero Administration Windows initiative and is required to conform to the Designed for Microsoft Windows logo standards. Some of the advanced features of the Windows Installer are self-repair, rollback, and install on demand. The Windows Installer comes packaged with Windows 2000 and above, and is available as a separate download for Windows 9x and Windows NT. The Windows Installer runs as a two-part installation utility that consists of a client engine and a system service. The client engine (MSIEXEC.EXE) runs with user privileges and provides the interface between the system and the installation service. MSIEXEC.EXE reads the instructions from the installation package (*.MSI) and passes them to the installation service (Windows Installer). The installation service enables the system to keep track of all program installations and system changes, providing for cleaner uninstalls. Because the installation service runs as a system service, it can be given various privileges to allow users to install their own applications.

Self-RepairWhen a program file becomes corrupted or missing, a program installed with the Windows Installer can identify these files and replace them automatically. This is a handy feature for those of us with troublesome users who like to attempt their own uninstalls.

RollbackThe Windows Installer rollback feature creates a temporary backup and script of any files changed during the installation p

Search related