In this walkthrough, you create a catalog for each image in a Windows image (.wim) file. You start by defining the directory that contains the .wim files and getting a list of all the .wim files in the directory. Then, you loop through each .wim file in this directory to get the Windows image information. Finally, you create a catalog for each image in the .wim file.

Procedures

Get the number of .wim files in the directory

  • Define the directory that contains the .wim files.

    string wimFolder = @"C:\myWorkingFolder";
    
  • Get the list of .wim files in the wimFolder directory.

    string[] wimfiles =
    Directory.GetFiles(wimFolder, @"*.wim");
    

Get the Windows image information

  • Create a CPI instance.

    Cpi cpiObj = Cpi.Instance;
    
  • Get the Windows image information for each image in the .wim file.

    WimInfo wimInfo = cpiObj.OpenWim(wimfile);
    

Create a catalog for each Image:

  • Loop through the images, validate the Windows image, and create a new catalog for each image in the .wim file.

    foreach (OfflineImageInfo imageInfo in wimInfo.Images)
    {
    	imageInfo.ValidateImage();
    	imageInfo.CreateCatalog();
    }
    

Example

The following example demonstrates how to create a catalog for each image in the .wim file.

noteNote:
To run this example, you must change the value of the variable wimFolder to match the path that contains the .wim files on your machine.
// CreateCatalogs.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.ComponentStudio.ComponentPlatformInterface;

namespace CreateCatalogs
{
	class CreateCatalog
	{
		static void Main(string[] args)
		{
			// Define the directory that contains .wim files:
			string wimFolder = @"C:\myWorkingFolder";

			// Get list of .wim files in the wimFolder directory:
			string[] wimfiles = 
				Directory.GetFiles(wimFolder, @"*.wim");

			// Display the number of .wim files:
			Console.WriteLine(
			"Number of .wim files in the folder {0} is {1}.",
			wimFolder, wimfiles.Length);

			// Loop through each .wim file in the folder:
			foreach (string wimfile in wimfiles)
			{
				// Display the path name of the .wim file:
				Console.WriteLine(
					"The .wim file path-name is: {0}"
					, wimfile);

				// Create a Cpi instance:
				Cpi cpiObj = Cpi.Instance;

				// By using the Cpi instance, get the Windows image
				// file information from the .wim file:
				WimInfo wimInfo = cpiObj.OpenWim(wimfile);

				// Loop through the images and create
				// a catalog for each image in the .wim file:
				foreach (OfflineImageInfo imageInfo 
					in wimInfo.Images)
				{
				 // Display the name of the image and the
				 // corresponding catalog:
					Console.WriteLine("Creating catalog for: " +
					imageInfo.ImageName);
					// Create the catalog:
					imageInfo.ValidateImage();
					imageInfo.CreateCatalog();
			 }
		}
	}
}
}

Output

Number of .wim files in the folder C:\myWorkingFolder is 1.
The .wim file path-name is: C:\myWorkingFolder\install.wim
The .wim information is: Microsoft.ComponentStudio.ComponentPlatformInterface.Wi
mInfo
Creating catalog for: Windows Vista ULTIMATE
Creating catalog for: Windows Vista BUSINESS
Creating catalog for: Windows Vista BUSINESSN
Creating catalog for: Windows Vista ENTERPRISE
Creating catalog for: Windows Vista HOMEBASICN
Creating catalog for: Windows Vista HOMEPREMIUM
Creating catalog for: Windows Vista STARTER

See Also