Skip to content
Jeff Kluge edited this page Jul 11, 2022 · 4 revisions

The DISM API files are available in all Windows® 8 operating systems. You can also run DISM API applications on any Windows operating system that is supported by the Windows ADK. You must install the Windows ADK in order to run DISM API applications on these operating systems. For more information about supported operating systems, see the Windows® Assessment and Deployment Kit (Windows ADK) Technical Reference.

How to use the wrapper

Install the NuGet package:

Install-Package Microsoft.Dism

Alternatively, download the compiled binaries or source code and add a reference to the assembly in Visual Studio. You can then call methods in the DismApi class.

The wrapper is as close to the native DismApi as possible. Most methods in the DismApi class should mirror the functions in the DismApi. Managed classes are used in place of the native structs and I tried to keep the property names the same. I also included XML doc comments on every class, method, and property which should help with development.

Initializing DISMAPI

You'll need to initialize the DismApi first (don't forget to call Shutdown() at the end of your program)

DismApi.Initialize(DismLogLevel.LogErrors);

DismApi.Shutdown();

List Images

An example on how to list the images contained in a WIM file:

// Path to the WIM file
string imagePath = @"C:\image.wim";

// Initialize the DismApi
DismApi.Initialize(DismLogLevel.LogErrors);

try
{
	// Get the images in the WIM
	DismImageInfoCollection imageInfos = DismApi.GetImageInfo(imagePath);

	// Print the image path and image count
	Console.WriteLine("Image {0} contains {1} image(s)", imagePath, imageInfos.Count);

	// Loop through each image
	foreach(DismImageInfo imageInfo in imageInfos)
	{
		// Print the image index and name
		Console.WriteLine("Image Index: {0}", imageInfo.ImageIndex);
		Console.WriteLine("Image Name: {0}", imageInfo.ImageName);
		Console.WriteLine("------------------------");
	}
}
finally
{
	// Shut down the DismApi
	DismApi.Shutdown();
}

Mounting Images

An example on how to mount an image, list the features, and unmount it:

string imagePath = @"C:\image.wim";
string mountPath = @"C:\temp\mount";
int imageIndex = 1;

// Initialize the DismApi
DismApi.Initialize(DismLogLevel.LogErrors);

try
{
	// Create the mount dir if it doesn't exit
	if(Directory.Exists(mountPath) == false)
	{
		Directory.Create(mountPath);
	}

	// Mount the image
	DismApi.MountImage(imagePath, mountPath, imageIndex);

	// Open a session to the mounted image
	using(DismSession session = DismApi.OpenOfflineSession(mountPath))
	{
		// Get the features of the image
		DismFeatureCollection features = DismApi.GetFeatures(session);

		// Loop through the features
		foreach(DismFeature feature in features)
		{
			// Print the feature name
			Console.WriteLine("Feature: {0}", feature.FeatureName);
		}
	}

	// Unmount the image and discard changes
	DismApi.UnmountImage(mountPath, false);
}
finally
{
	// Shut down the DismApi
	DismApi.Shutdown();
}
Clone this wiki locally