Esempio n. 1
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);
        }
Esempio n. 2
0
 public static extern int DismGetFeatureInfo(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier, out IntPtr pFeatureInfo);
 public static extern int DismGetFeatureParent(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier, out IntPtr feature, out UInt32 count);
        /// <summary>
        /// Gets the parent features of a specified feature.
        /// </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 OpenSession Function.</param>
        /// <param name="featureName">The name of the feature that you want to find the parent of.</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">Optional. A valid DismPackageIdentifier Enumeration value.</param>
        /// <returns>A <see cref="DismFeatureCollection"/> object containing a collection of <see cref="DismFeature"/> objects.</returns>
        private static DismFeatureCollection GetFeatureParent(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier)
        {
            var features = new DismFeatureCollection();

            int hresult = NativeMethods.DismGetFeatureParent(session, featureName, identifier, packageIdentifier, out IntPtr featurePtr, out UInt32 featureCount);

            try
            {
                DismUtilities.ThrowIfFail(hresult, session);

                // Add the items
                features.AddRange <DismApi.DismFeature_>(featurePtr, (int)featureCount, i => new DismFeature(i));
            }
            finally
            {
                // Clean up
                DismApi.Delete(featurePtr);
            }

            return(features);
        }
Esempio n. 5
0
 public static extern int DismRemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
Esempio n. 6
0
 public static extern int DismGetPackageInfo(DismSession dismSession, string identifier, DismPackageIdentifier packageIdentifier, out IntPtr packageInfo);
Esempio n. 7
0
        /// <summary>
        /// Gets extended information about a package.
        /// </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 OpenImageSession 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 valid DismPackageIdentifier Enumeration value.</param>
        /// <returns>A <see cref="DismPackageInfo" /> object.</returns>
        private static DismPackageInfo GetPackageInfo(DismSession session, string identifier, DismPackageIdentifier packageIdentifier)
        {
            int hresult = NativeMethods.DismGetPackageInfo(session, identifier, packageIdentifier, out IntPtr packageInfoPtr);

            try
            {
                DismUtilities.ThrowIfFail(hresult, session);

                // Return a new DismPackageInfo object with a reference to the pointer
                return(new DismPackageInfo(packageInfoPtr));
            }
            finally
            {
                // Clean up
                Delete(packageInfoPtr);
            }
        }
Esempio n. 8
0
 public static extern int DismEnableFeature(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths, UInt32 sourcePathCount, [MarshalAs(UnmanagedType.Bool)] bool enableAll, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
Esempio n. 9
0
        /// <summary>
        /// Enables a feature from the specified package path.
        /// </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="featureName">The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.</param>
        /// <param name="identifier">A package name or absolute path.</param>
        /// <param name="packageIdentifier">A DismPackageIdentifier value.</param>
        /// <param name="limitAccess">Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. 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 required to enable the feature are still present on the computer, this flag is ignored.</param>
        /// <param name="enableAll">Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.</param>
        /// <param name="sourcePaths">A list of source locations to check for files needed to enable the feature.</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>
        private static void EnableFeature(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List <string> sourcePaths, Microsoft.Dism.DismProgressCallback progressCallback, object userData)
        {
            // Get the list of source paths as an array
            string[] 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.DismEnableFeature(
                session: session,
                featureName: featureName,
                identifier: identifier,
                packageIdentifier: identifier == null ? DismPackageIdentifier.None : packageIdentifier,
                limitAccess: limitAccess,
                sourcePaths: sourcePathsArray,
                sourcePathCount: (uint)sourcePathsArray.Length,
                enableAll: enableAll,
                cancelEvent: progress.EventHandle,
                progress: progress.DismProgressCallbackNative,
                userData: IntPtr.Zero);

            DismUtilities.ThrowIfFail(hresult, session);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the parent features of a specified feature.
        /// </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 OpenSession Function.</param>
        /// <param name="featureName">The name of the feature that you want to find the parent of.</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">Optional. A valid DismPackageIdentifier Enumeration value.</param>
        /// <returns>A <see cref="DismFeatureCollection" /> object containing a collection of <see cref="DismFeature" /> objects.</returns>
        private static DismFeatureCollection GetFeatureParent(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier)
        {
            int hresult = NativeMethods.DismGetFeatureParent(session, featureName, identifier, packageIdentifier, out IntPtr featurePtr, out UInt32 featureCount);

            try
            {
                DismUtilities.ThrowIfFail(hresult, session);

                return(new DismFeatureCollection(featurePtr, featureCount));
            }
            finally
            {
                // Clean up
                Delete(featurePtr);
            }
        }
        /// <summary>
        /// Gets detailed information for the specified feature.
        /// </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="featureName">The name of the feature that you want to get more information about.</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 valid DismPackageIdentifier Enumeration value.</param>
        /// <returns>A <see cref="DismFeatureInfo"/> object.</returns>
        private static DismFeatureInfo GetFeatureInfo(DismSession session, string featureName, string identifier, DismPackageIdentifier packageIdentifier)
        {
            int hresult = NativeMethods.DismGetFeatureInfo(session, featureName, identifier, packageIdentifier, out IntPtr featureInfoPtr);

            try
            {
                DismUtilities.ThrowIfFail(hresult, session);

                // Return a new DismFeatureInfo from the native pointer
                return(new DismFeatureInfo(featureInfoPtr));
            }
            finally
            {
                // Clean up the native pointer
                DismApi.Delete(featureInfoPtr);
            }
        }