Example #1
0
        /// <summary>
        /// Mount the Wim and set UI to mounted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mountWimButtom_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(wimFileTextBox.Text) || !String.IsNullOrEmpty(exportPathTextBox.Text) || !String.IsNullOrEmpty(indexTextBox.Text))
            {
                DismApi.Initialize(DismLogLevel.LogErrors);
                Task t = Task.Factory.StartNew(() =>
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = true;
                            mainPanel.Enabled = false;
                            mainPanel.Visible = false;
                            uiControlMounted(true);
                        }));
                    }
                    try
                    {
                        DismMountImageOptions s = new DismMountImageOptions();
                        string imagePath        = wimFileTextBox.Text;
                        string mountPath        = exportPathTextBox.Text;
                        int imageIndex          = Convert.ToInt32(indexTextBox.Text);

                        // Create the mount dir if it doesn't exit
                        if (Directory.Exists(mountPath) == false)
                        {
                            Directory.CreateDirectory(mountPath);
                        }
                        // Mount the image
                        DismApi.MountImage(imagePath, mountPath, imageIndex, false, s, dismProgress_action);
                        MountPath = mountPath;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        if (this.InvokeRequired)
                        {
                            this.Invoke((MethodInvoker)(() =>
                            {
                                loadingPanel.Visible = false;
                                mainPanel.Enabled = true;
                                mainPanel.Visible = true;
                            }));
                        }
                        // Shut down the DismApi
                        DismApi.Shutdown();
                    }
                });
            }
            else
            {
                MessageBox.Show("Please Select the WIM Folder and Mount Folder paths. DISM Approves");
            }
        }
Example #2
0
 /// <summary>
 /// Mounts a WIM or VHD image file to a specified location.
 /// </summary>
 /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
 /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
 /// <param name="imageIndex">The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.</param>
 /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
 /// <param name="options">Specifies options to use when mounting an image.</param>
 /// <param name="progressCallback">A progress callback method to invoke when progress is made.</param>
 /// <exception cref="DismException">When a failure occurs.</exception>
 /// <exception cref="OperationCanceledException">When the user requested the operation be canceled.</exception>
 public static void MountImage(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options, Dism.DismProgressCallback progressCallback)
 {
     DismApi.MountImage(imageFilePath, mountPath, imageIndex, readOnly, options, progressCallback, null);
 }
Example #3
0
 /// <summary>
 /// Mounts a WIM or VHD image file to a specified location.
 /// </summary>
 /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
 /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
 /// <param name="imageIndex">The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.</param>
 /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
 /// <param name="options">Specifies options to use when mounting an image.</param>
 /// <exception cref="DismException">When a failure occurs.</exception>
 public static void MountImage(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options)
 {
     DismApi.MountImage(imageFilePath, mountPath, imageIndex, readOnly, options, null);
 }
Example #4
0
        /// <summary>
        /// Mounts a WIM or VHD image file to a specified location.
        /// </summary>
        /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
        /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
        /// <param name="imageIndex">The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.</param>
        /// <param name="imageName">The name of the image that you want to mount.</param>
        /// <param name="imageIdentifier">A DismImageIdentifier Enumeration value such as DismImageIndex.</param>
        /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
        /// <param name="options">Specifies options to use when mounting an image.</param>
        /// <param name="progressCallback">A progress callback method to invoke when progress is made.</param>
        /// <param name="userData">Optional user data to pass to the DismProgressCallback method.</param>
        private static void MountImage(string imageFilePath, string mountPath, int imageIndex, string imageName, DismImageIdentifier imageIdentifier, bool readOnly, DismMountImageOptions options, Microsoft.Dism.DismProgressCallback progressCallback, object userData)
        {
            // Determine the flags to pass to the native call
            var flags = (readOnly ? DismApi.DISM_MOUNT_READONLY : DismApi.DISM_MOUNT_READWRITE) | (uint)options;

            // Create a DismProgress object to wrap the callback and allow cancellation
            var progress = new DismProgress(progressCallback, userData);

            int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult);
        }
Example #5
0
 /// <summary>
 /// Mounts a WIM or VHD image file to a specified location.
 /// </summary>
 /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
 /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
 /// <param name="imageName">The name of the image that you want to mount.</param>
 /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
 /// <param name="options">Specifies options to use when mounting an image.</param>
 /// <param name="progressCallback">A progress callback method to invoke when progress is made.</param>
 /// <param name="userData">Optional user data to pass to the DismProgressCallback method.</param>
 /// <exception cref="DismException">When a failure occurs.</exception>
 /// <exception cref="OperationCanceledException">When the user requested the operation be canceled.</exception>
 public static void MountImage(string imageFilePath, string mountPath, string imageName, bool readOnly, DismMountImageOptions options, Dism.DismProgressCallback progressCallback, object userData)
 {
     DismApi.MountImage(imageFilePath, mountPath, 0, imageName, DismImageIdentifier.ImageName, readOnly, options, progressCallback, userData);
 }
Example #6
0
 /// <summary>
 /// Mounts a WIM or VHD image file to a specified location.
 /// </summary>
 /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
 /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
 /// <param name="imageName">The name of the image that you want to mount.</param>
 /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
 /// <param name="options">Specifies options to use when mounting an image.</param>
 /// <exception cref="DismException">When a failure occurs.</exception>
 public static void MountImage(string imageFilePath, string mountPath, string imageName, bool readOnly, DismMountImageOptions options)
 {
     MountImage(imageFilePath, mountPath, imageName, readOnly, options, null);
 }
Example #7
0
 /// <summary>
 /// Mounts a WIM or VHD image file to a specified location.
 /// </summary>
 /// <param name="imageFilePath">The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.</param>
 /// <param name="mountPath">The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.</param>
 /// <param name="imageIndex">The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.</param>
 /// <param name="readOnly">Specifies if the image should be mounted in read-only mode.</param>
 /// <param name="options">Specifies options to use when mounting an image.</param>
 /// <param name="progressCallback">A progress callback method to invoke when progress is made.</param>
 /// <param name="userData">Optional user data to pass to the DismProgressCallback method.</param>
 /// <exception cref="DismException">When a failure occurs.</exception>
 /// <exception cref="OperationCanceledException">When the user requested the operation be canceled.</exception>
 public static void MountImage(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options, Dism.DismProgressCallback progressCallback, object userData)
 {
     MountImage(imageFilePath, mountPath, imageIndex, null, DismImageIdentifier.ImageIndex, readOnly, options, progressCallback, userData);
 }