DESKTOP

Windows Vista : Managing Windows Images - Executing Common Tasks (part 2) - Incorporating scripts in a Windows PE image

10/18/2012 4:16:21 AM

6. Incorporating scripts in a Windows PE image

It is recommenced that you keep your actual script on an accessible network share and not within the Windows PE image so that you may easily test and modify it without a need to rebuild and deploy the WIM.

There are a couple of ways to trigger the execution of scripts:

  • Edit the StartNet script to perform actions or call your own script

  • Change the default shell to that of your own script

Editing the StartNet script

Editing the StartNet script (STARTNET.CMD) is the easiest and most effective way to customize Windows PE startup actions. You may edit the script directly or you may have this script make a call to one of your own. If you are familiar with a batch file (.BAT), a CMD file is the very same thing.

The script is located at C:\winpe_x86\mount\Windows\System32\Startnet.cmd. By default, the script contains a comment and one command: wpeinit. Wpeinit is a command line tool that initializes Windows PE each time it boots. It installs PnP devices, processes Unattend.xml settings, and loads network resources.

Specifying an alternate shell

The default shell that is called by Windows PE is cmd.exe (the command prompt). You can, however, change this behavior to launch your own script or supported executable.

To specify an alternate shell, follow these steps:

  1. With the image mounted for read/write (/MountRW), run notepad.exe and enter the following text in a new file to be saved in the Windows\System32 folder of your mounted image as "myscript.cmd" (C:\winpe_x86\mount\Windows\System32\myscript.cmd)

    @echo off
    echo starting network...
    wpeinit
    echo mapping network drive...
    net use q: \\server\share\tools Password1 /USER:appdeploy\
       bkelly
    echo launching new cmd instance...
    cmd /k
    echo Ready to reboot.
    pause

  2. Create a second file in Notepad to be saved in the same location with a name of winpeshl.ini(C:\winpe_x86\mount\Windows\System32\winpeshl.ini) and enter the following text:

    [LaunchApp]
    AppPath = %SYSTEMROOT%\System32\myscript.cmd

    NOTE

    The AppPath entry does not support command line options.

  3. After you are done editing your image, commit the changes back to the mounted image using the ImageX Unmount command:

    Imagex /Unmount /Commit c:\winpe_x86\mount

When the shell closes, Windows PE reboots, so make sure to control the completion of your script.


After following the above steps, Windows PE will run the script that initializes the network, map drive Q to a network share, and then start a new command shell so that the user can perform actions without the script closing (see Figure 1). If the script were to close, the computer would be restarted. This method allows the user to enter commands, and when done, typing exit would return them to the script (where they would see the Ready to reboot message).

Figure 1. Testing automatic startup commands with a custom shell

7. Create a bootable ISO from WIM image

Creating a bootable ISO image is a typical final step in customizing Windows PE. You can burn this to a CD or DVD to use in production. For testing, a virtual machine is the perfect tool due to a common feature that allows you to mount an ISO as a virtual disk from which you can easily boot.

With the details of each of these command lines already covered, here is an example of using these tools to get your edited image in the form of an ISO.

  1. Unmount the image and commit any changes:

    imagex /unmount /commit c:\winpe_x86\mount

  2. Copy the updated Windows PE image over the existing boot.wim in the ISO sources directory (answer yes if asked to confirm the overwriting of the file):

    copy c:\winpe_x86\winpe.wim c:\winpe_x86\iso\sources\boot.wim

  3. Use the OSCDImg command line tool discussed earlier to generate the ISO:

    oscdimg -n -bc:\winpe_x86\etfsboot.com c:\winpe_x86\ISO c:\
       winpe_x86\winpe_x86.iso

8. Configure a UFD to boot to Windows PE

A USB flash drive (UFD) can be a handy deployment mechanism for Windows PE as compared to a CD or DVD in that it can hold more, it can be accessed more quickly, and it fits much better in your pocket. Not all computers will support booting from a USB device, but most new computer motherboards do offer such support. Enter your BIOS menu at startup to see what boot devices are available (you can typically reorder such devices to dictate priority).

  1. Unmount the image and commit any changes:

    imagex /unmount /commit c:\winpe_x86\mount

  2. Copy the updated Windows PE image over the existing boot.wim in the ISO sources directory (answer yes if asked to confirm the overwriting of the file):

    copy c:\winpe_x86\winpe.wim c:\winpe_x86\iso\sources\boot.wim

  3. Now launch a command prompt as administrator by right-clicking the command prompt icon and choosing Run as administrator.

  4. To launch the DiskPart command line tool, type:

    DISKPART

  5. List the available disks to determine which is that of your UFD. It is very important that you determine the proper disk number because all data will be removed from the specified disk when following these steps. To list the disks, type the following command and, based on its capacity, note the number that corresponds with your UFD (see Figure 2):

    LIST DISK

    Figure 2. Reviewing listed disks to determine which your UFD is
  6. Select the disk by number based on what was determined to be the correct drive in the previous step (be certain to select the correct disk!):

    SELECT DISK 5

  7. Now that the proper disk is selected, prepare it with the clean command:

    CLEAN

  8. Now create a partition on the clean drive:

    CREATE PARTITION PRIMARY

  9. Select the newly created partition:

    SELECT PARTITION 1

  10. Set the partition as active with the Active command:

    ACTIVE

  11. Format the partition with the Format command:

    FORMAT

  12. Assign the new partition with the Assign command:

    ASSIGN

  13. To quit DiskPart use the Exit command:

    EXIT

  14. Now copy to the contents of the c:\winpe_x86\ISO folder to the USB disk. In the following sample command, the USB disk is on the E drive (substitute as needed):

    XCOPY C:\WINPE_X86\ISO\*.* E: /E

NOTE

If you have trouble locating your drive, go back into DiskPart, select the disk and the volume and then run the Assign command again using the optional argument Letter to specify a specific drive letter:

ASSIGN LETTER=E

There are situations where this is necessary, for example, when a disconnected network drive was mistakenly assigned the same drive as the UFD. Specifying an explicit drive letter like this will alleviate any such problems.

Now you should be able to boot from the USB flash disk. Make sure to select the right boot device during the boot cycle or to change the boot order in your computer's BIOS.

Other  
 
Most View
Installing or Upgrading Windows 8 : Dual- (and Multi-) Booting Windows 8 (part 2) - Using Windows Boot Manager
HIS Radeon HD 7970 3GB X Turbo - Massive Overclock And A New Cooler
Cookie D'oh, I Scream
Buying Guide: Mid-Price Flashguns (Part 2) : Nissin D1866 Mark Ii, Sigma EF-610 DG Super, Sunpak PZ42X
Microsoft Exchange Server 2010 : Creating and Managing E-Mail Address Policies (part 3) - Editing and Applying E-Mail Address Policies , Removing E-Mail Address Policies
Sharepoint 2013 : Introducing JavaScript for SharePoint developers (part 1) - Understanding JavaScript namespaces, Understanding JavaScript variables
How The Internet Of Things Will Change Your Life (Part 2) - Samsung T9000 Refrigerator
OpenGL on OS X : CGL
Installing Windows 8 on a new or formatted system (part 3) - Installing Windows 8 with Windows To Go
Panasonic Super Zoom Lumix FZ200
Top 10
SQL Server 2012 : Policy Based Management - Evaluating Policies
SQL Server 2012 : Defining Policies (part 3) - Creating Policies
SQL Server 2012 : Defining Policies (part 2) - Conditions
SQL Server 2012 : Defining Policies (part 1) - Management Facets
Microsoft Exchange Server 2010 : Configuring Anti-Spam and Message Filtering Options (part 4) - Preventing Internal Servers from Being Filtered
Microsoft Exchange Server 2010 : Configuring Anti-Spam and Message Filtering Options (part 3) - Defining Block List Exceptions and Global Allow/Block Lists
Microsoft Exchange Server 2010 : Configuring Anti-Spam and Message Filtering Options (part 2) - Filtering Connections with IP Block Lists
Microsoft Exchange Server 2010 : Configuring Anti-Spam and Message Filtering Options (part 1) - Filtering Spam and Other Unwanted E-Mail by Sender, Filtering Spam and Other Unwanted E-Mail by Recipien
Microsoft Exchange Server 2010 : Creating and Managing Remote Domains (part 3) - Configuring Messaging Options for Remote Domains , Removing Remote Domains
Microsoft Exchange Server 2010 : Creating and Managing Remote Domains (part 2) - Creating Remote Domains