/// <summary> /// Gets the error message in the current thread immediately after a failure. /// </summary> /// <returns>An error message if one is found, otherwise null.</returns> public static string GetLastErrorMessage() { // Allow this method to be overridden by an internal test hook if (GetLastErrorMessageTestHook != null) { return(GetLastErrorMessageTestHook()); } if (NativeMethods.DismGetLastErrorMessage(out IntPtr errorMessagePtr) != DismApi.ERROR_SUCCESS) { return(null); } try { // Get a string from the pointer string dismString = errorMessagePtr.ToStructure <DismApi.DismString>(); // See if the string has a value if (String.IsNullOrEmpty(dismString) == false) { // Return the trimmed value return(dismString.Trim()); } } finally { // Clean up DismApi.Delete(errorMessagePtr); } // No error message was found return(null); }
/// <summary> /// Gets DISM capability info. /// </summary> /// <param name="session">A valid DismSession. The DismSession must be associated with an image. You can associate a session with an image by using the <see cref="OpenOfflineSession(string)"/> method.</param> /// <param name="capabilityName">The name of the specified capability.</param> /// <returns>A <see cref="DismCapabilityInfo"/> object.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismCapabilityInfo GetCapabilityInfo(DismSession session, string capabilityName) { int hresult = NativeMethods.DismGetCapabilityInfo(session, capabilityName, out IntPtr capabilityInfoPtr); try { DismUtilities.ThrowIfFail(hresult, session); // Return a new DismCapabilityInfo from the native pointer return(new DismCapabilityInfo(capabilityInfoPtr)); } finally { // Clean up the native pointer DismApi.Delete(capabilityInfoPtr); } }
/// <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 DismApi.Delete(packageInfoPtr); } }
/// <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); } }
/// <summary> /// Gets information about app packages (.appx) in an image that will be installed for each new user. /// </summary> /// <param name="session">A valid DISM Session.</param> /// <returns>A <see cref="DismAppxPackageCollection"/> object containing a collection of <see cref="DismAppxPackage"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> /// <exception cref="DismRebootRequiredException">When the operation requires a reboot to complete.</exception> public static DismAppxPackageCollection GetProvisionedAppxPackages(DismSession session) { var appxPackages = new DismAppxPackageCollection(); int hresult = NativeMethods._DismGetProvisionedAppxPackages(session, out IntPtr appxPackagesPtr, out UInt32 appxPackagesCount); try { DismUtilities.ThrowIfFail(hresult, session); appxPackages.AddRange <DismApi.DismAppxPackage_>(appxPackagesPtr, (int)appxPackagesCount, i => new DismAppxPackage(i)); } finally { DismApi.Delete(appxPackagesPtr); } return(appxPackages); }
/// <summary> /// Gets DISM capabilities. /// </summary> /// <param name="session">A valid DismSession. The DismSession must be associated with an image. You can associate a session with an image by using the <see cref="OpenOfflineSession(string)"/> method.</param> /// <returns>A <see cref="DismCapabilityCollection"/> object containing a collection of <see cref="DismCapability"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismCapabilityCollection GetCapabilities(DismSession session) { DismCapabilityCollection capabilities = new DismCapabilityCollection(); int hresult = NativeMethods.DismGetCapabilities(session, out IntPtr capabilityPtr, out UInt32 capabilityCount); try { DismUtilities.ThrowIfFail(hresult, session); // Add the items capabilities.AddRange <DismCapability_>(capabilityPtr, (int)capabilityCount, c => new DismCapability(c)); } finally { DismApi.Delete(capabilityPtr); } return(capabilities); }
/// <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); }
/// <summary> /// Gets a list of images that are currently mounted. /// </summary> /// <returns>A <see cref="DismMountedImageInfoCollection"/> object containing a collection of <see cref="DismMountedImageInfo"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismMountedImageInfoCollection GetMountedImages() { var mountedImageInfos = new DismMountedImageInfoCollection(); int hresult = NativeMethods.DismGetMountedImageInfo(out IntPtr mountedImageInfoPtr, out UInt32 mountedImageInfoCount); try { DismUtilities.ThrowIfFail(hresult); // Add the items mountedImageInfos.AddRange <DismApi.DismMountedImageInfo_>(mountedImageInfoPtr, (int)mountedImageInfoCount, i => new DismMountedImageInfo(i)); } finally { // Clean up DismApi.Delete(mountedImageInfoPtr); } return(mountedImageInfos); }
/// <summary> /// Gets the drivers in 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 <see cref="OpenOfflineSession(string)"/> method.</param> /// <param name="allDrivers">true or false to specify to retrieve all drivers or just out-of-box drivers.</param> /// <returns>A <see cref="DismDriverPackageCollection"/> object containing a collection of <see cref="DismDriverPackage"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismDriverPackageCollection GetDrivers(DismSession session, bool allDrivers) { var driverPackages = new DismDriverPackageCollection(); int hresult = NativeMethods.DismGetDrivers(session, allDrivers, out IntPtr driverPackagePtr, out UInt32 driverPackageCount); try { DismUtilities.ThrowIfFail(hresult, session); // Add the items driverPackages.AddRange <DismApi.DismDriverPackage_>(driverPackagePtr, (int)driverPackageCount, i => new DismDriverPackage(i)); } finally { // Clean up DismApi.Delete(driverPackagePtr); } return(driverPackages); }
/// <summary> /// Gets a collection of each package in an image and provides basic information about each package, such as the package name and type of package. /// </summary> /// <param name="session">A valid DISM Session. The DismSession must be associated with an image.</param> /// <returns>A <see cref="DismPackageCollection"/> object containing a collection of <see cref="DismPackage"/>objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismPackageCollection GetPackages(DismSession session) { var packages = new DismPackageCollection(); int hresult = NativeMethods.DismGetPackages(session, out IntPtr packagePtr, out UInt32 packageCount); try { DismUtilities.ThrowIfFail(hresult, session); // Add the items packages.AddRange <DismApi.DismPackage_>(packagePtr, (int)packageCount, i => new DismPackage(i)); } finally { // Clean up DismApi.Delete(packagePtr); } return(packages); }
/// <summary> /// Gets a collection of images contained in the specified .wim or .vhd file. /// </summary> /// <param name="imageFilePath">// Clean up</param> /// <returns>A <see cref="DismImageInfoCollection"/> object containing a collection of <see cref="DismImageInfo"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismImageInfoCollection GetImageInfo(string imageFilePath) { var imageInfos = new DismImageInfoCollection(); int hresult = NativeMethods.DismGetImageInfo(imageFilePath, out IntPtr imageInfoPtr, out UInt32 imageInfoCount); try { DismUtilities.ThrowIfFail(hresult); // Add the items imageInfos.AddRange <DismApi.DismImageInfo_>(imageInfoPtr, (int)imageInfoCount, i => new DismImageInfo(i)); } finally { // Clean up DismApi.Delete(imageInfoPtr); } return(imageInfos); }
/// <summary> /// Gets information about an .inf file in a specified 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 <see cref="OpenOfflineSession(string)"/> method.</param> /// <param name="driverPath">A relative or absolute path to the driver .inf file.</param> /// <returns>A <see cref="DismDriverCollection"/> object containing a collection of <see cref="DismDriver"/> objects.</returns> /// <exception cref="DismException">When a failure occurs.</exception> public static DismDriverCollection GetDriverInfo(DismSession session, string driverPath) { var driverInfos = new DismDriverCollection(); int hresult = NativeMethods.DismGetDriverInfo(session, driverPath, out IntPtr driverInfoPtr, out UInt32 driverInfoCount, out IntPtr driverPackagePtr); try { DismUtilities.ThrowIfFail(hresult, session); // Add the items driverInfos.AddRange <DismApi.DismDriver_>(driverInfoPtr, (int)driverInfoCount, i => new DismDriver(i)); } finally { // Clean up DismApi.Delete(driverInfoPtr); DismApi.Delete(driverPackagePtr); } return(driverInfos); }