sbeisner
sbeisner

Reputation: 23

Using DISM Api to Capture Image Programatically within Windows PE Environment

I've been going through the windows documentation for the Dism API with the goal of writing an exe in C++ (or whatever language can accomplish this) that can create a WIM image while running in Windows PE. I found a .NET Wrapper for the Dism API that seems like it might be useful for this purpose, but I'm unsure if a .NET app will successfully run in Windows PE. Overall, my problem is that I don't see a function that can create--and doesn't simply modify--a wim file.

If I didn't care about encapsulating this in an .exe file, the Dism documentation does show how to initially create a wim--which makes me curious why a similar function wouldn't exist within the api. Please advise if the simplest solution is to have my code call a function such as system() within the code.

To summarize, I'm looking for a way to create a wim file programmatically (called from executing an exe file) from within Windows PE.

As always, thank you for the help and advice.

Upvotes: 1

Views: 938

Answers (2)

creg
creg

Reputation: 164

Even though this post is a bit older, here is a possibly still relevant resource for you. Perhaps this one will help.

I've written a small GUI-based tool, project-named WIM-Backup, that uses the Windows Imaging Format (WIM) to create full backups of computer systems (operating system images) within WinPE and then restore them.

The application is hosted on GitHub, is open source, and is offered under the Apache 2.0 license.

In addition, the repository includes an illustrated step-by-step guide to help get it up and running.

WIM-Backup-Tool

Brief summary:

  • WIM-Backup always requires an external bootable media such as a USB flash drive.
  • From this drive WinPE is booted to perform a backup or restore to or from an external medium (e.g. a USB hard drive).
  • On the bootable USB flash drive the WinPE must be set up before (is documented illustrated in the readme).
  • After completion of the respective operation, a status message is displayed whether the operation was successful or failed.
  • After restoring a backup, you can boot normally from the destination drive.
  • Both the backup and restore process are relatively simple (not "rocket science").
  • To set up the solution, you need about 30 minutes time in the best case due to the necessary downloads (e .g. ADK)
  • Last but not least: it has a permissive license (non-proprietary) and is open source.

The project can be found here: WIM-Backup

Upvotes: 0

Clay
Clay

Reputation: 5084

I work on a project that works with DISM in WinPE quite a bit. We configure WinPE with all the .net packages as described here. Then WinPE can be configured to start an application.

I use c#, but you can do managed apps in c++ as I'm sure you know. I find putting c# code into WinPE substantially easier, but that's more a function of my experience, I suppose.

The main way we use to interact with DISM is run a command using System.Diagnostics.Process. The process runs in a separate thread, but the API is simple, and you can wait on (and/or timeout) your process for synchronization purposes. This just uses the DISM command line interface, although you can also use powershell cmdlets if you've added that package to your WinPE image. It may seem like a hacky "interface" from your app to DISM, but it works reliably, and you can keep the process window from showing up on the screen. This makes for a decent asynchronous platform for running bunches of windows imaging utilities, such as DISKPART, DISM and BCDEDIT.

The principal way you'd capture a new image is with DISM /Capture-Image. Sounds like you've already discovered this fact. Lots of options that are somewhat beyond the scope of this q/a, but I hope this gets you on a useful path.

Upvotes: 3

Related Questions