Ejemplo n.º 1
0
        /// <summary>
        /// Unmounts a Windows image from a specified location.
        /// </summary>
        /// <param name="mountPath">A relative or absolute path to the mount directory of the image.</param>
        /// <param name="commitChanges">Specifies whether or not the changes to the image should be saved.</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 UnmountImage(string mountPath, bool commitChanges, Dism.DismProgressCallback progressCallback, object userData)
        {
            // Determine flags
            var flags = commitChanges ? DismApi.DISM_COMMIT_IMAGE : DismApi.DISM_DISCARD_IMAGE;

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

            int hresult = NativeMethods.DismUnmountImage(mountPath, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes a package from an image.
 /// </summary>
 /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
 /// <param name="packagePath">The package path.</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>
 /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
 public static void RemovePackageByPath(DismSession session, string packagePath, Dism.DismProgressCallback progressCallback, object userData)
 {
     DismApi.RemovePackage(session, packagePath, DismPackageIdentifier.Path, progressCallback, userData);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Removes a package from an image.
 /// </summary>
 /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
 /// <param name="packagePath">The package path.</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>
 /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
 public static void RemovePackageByPath(DismSession session, string packagePath, Dism.DismProgressCallback progressCallback)
 {
     DismApi.RemovePackageByPath(session, packagePath, progressCallback, null);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes a package from an image.
        /// </summary>
        /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
        /// <param name="identifier">Either an absolute path to a .cab file or the package name, depending on the PackageIdentifier parameter value.</param>
        /// <param name="packageIdentifier">A DismPackageIdentifier Enumeration.</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 RemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, Dism.DismProgressCallback progressCallback, object userData)
        {
            // Create a DismProgress object to wrap the callback and allow cancellation
            var progress = new DismProgress(progressCallback, userData);

            int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult, session);
        }
        /// <summary>
        /// Repairs a corrupted image that has been identified as repairable by the CheckImageHealth Function.
        /// </summary>
        /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
        /// <param name="limitAccess">Specifies whether the RestoreImageHealth method should contact Windows Update (WU) as a source location for downloading repair files. Before checking WU, DISM will check for the files in the sourcePaths provided and in any locations specified in the registry by Group Policy. If the files that are required to enable the feature are found in these other specified locations, this flag is ignored.</param>
        /// <param name="sourcePaths">List of source locations to check for repair files.</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>
        /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
        public static void RestoreImageHealth(DismSession session, bool limitAccess, List <string> sourcePaths, Dism.DismProgressCallback progressCallback, object userData)
        {
            // Get the list of source paths as an array
            var sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];

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

            int hresult = NativeMethods.DismRestoreImageHealth(session, sourcePathsArray, (uint)sourcePathsArray.Length, limitAccess, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult, session);
        }
 /// <summary>
 /// Repairs a corrupted image that has been identified as repairable by the CheckImageHealth Function.
 /// </summary>
 /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
 /// <param name="limitAccess">Specifies whether the RestoreImageHealth method should contact Windows Update (WU) as a source location for downloading repair files. Before checking WU, DISM will check for the files in the sourcePaths provided and in any locations specified in the registry by Group Policy. If the files that are required to enable the feature are found in these other specified locations, this flag is ignored.</param>
 /// <param name="sourcePaths">List of source locations to check for repair files.</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>
 /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
 public static void RestoreImageHealth(DismSession session, bool limitAccess, List <string> sourcePaths, Dism.DismProgressCallback progressCallback)
 {
     DismApi.RestoreImageHealth(session, limitAccess, sourcePaths, progressCallback, null);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Removes a package from an image.
 /// </summary>
 /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
 /// <param name="packageName">The package name.</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>
 /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
 public static void RemovePackageByName(DismSession session, string packageName, Dism.DismProgressCallback progressCallback, object userData)
 {
     RemovePackage(session, packageName, DismPackageIdentifier.Name, progressCallback, userData);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Removes the capability from an image.
        /// </summary>
        /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
        /// <param name="capabilityName">The name of the capability that is being removed</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>
        /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
        public static void RemoveCapability(DismSession session, string capabilityName, Dism.DismProgressCallback progressCallback, object userData)
        {
            // Create a DismProgress object to wrap the callback and allow cancellation
            DismProgress progress = new DismProgress(progressCallback, userData);

            int hresult = NativeMethods.DismRemoveCapability(session, capabilityName, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult, session);
        }
Ejemplo n.º 9
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="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, Dism.DismProgressCallback progressCallback, object userData)
 {
     DismApi.MountImage(imageFilePath, mountPath, imageIndex, readOnly, DismMountImageOptions.None, progressCallback, userData);
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
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="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, string imageName, bool readOnly, Dism.DismProgressCallback progressCallback)
 {
     DismApi.MountImage(imageFilePath, mountPath, imageName, readOnly, DismMountImageOptions.None, progressCallback);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Unmounts a Windows image from a specified location.
 /// </summary>
 /// <param name="mountPath">A relative or absolute path to the mount directory of the image.</param>
 /// <param name="commitChanges">Specifies whether or not the changes to the image should be saved.</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 UnmountImage(string mountPath, bool commitChanges, Dism.DismProgressCallback progressCallback)
 {
     DismApi.UnmountImage(mountPath, commitChanges, progressCallback, null);
 }
Ejemplo n.º 14
0
 public static void SetEdition(DismSession session, string editionID, string productKey, Dism.DismProgressCallback progressCallback)
 {
     SetEdition(session, editionID, productKey, progressCallback, null);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Removes a package from an image.
 /// </summary>
 /// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.</param>
 /// <param name="packageName">The package name.</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>
 /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception>
 public static void RemovePackageByName(DismSession session, string packageName, Dism.DismProgressCallback progressCallback)
 {
     RemovePackageByName(session, packageName, progressCallback, null);
 }
Ejemplo n.º 16
0
        private static void SetEdition(DismSession session, string editionID, string productKey, Dism.DismProgressCallback progressCallback, object userData)
        {
            // Create a DismProgress object to wrap the callback and allow cancellation
            DismProgress progress = new DismProgress(progressCallback, userData);

            int hresult = NativeMethods._DismSetEdition(session, editionID, productKey, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult, session);
        }
Ejemplo n.º 17
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);
 }