コード例 #1
0
        public bool AddDriver(string infFullPath, bool install)
        {
            switch (this.Type)
            {
            case DriverStoreType.Online:
                return(SetupAPI.AddDriver(infFullPath, install));

            case DriverStoreType.Offline:
                DismApi.Initialize(DismLogLevel.LogErrors);

                try
                {
                    using (DismSession session = this.GetSession())
                    {
                        DismApi.AddDriver(session, infFullPath, false);
                    }
                }
                finally
                {
                    DismApi.Shutdown();
                }

                return(true);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #2
0
ファイル: InternetExplorer.cs プロジェクト: wellswitch/chemo
        public override bool PerformTreatment()
        {
            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    try
                    {
                        DismApi.DisableFeature(session, resolvedFeatureName, null, true);
                    }
                    catch (DismRebootRequiredException ex)
                    {
                        Logger.Log("Successfully disabled Internet Explorer 11. {0}", ex.Message);
                        return(true);
                    }

                    Logger.Log("Successfully disabled Internet Explorer 11.");
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Log("An error occurred while disabling Internet Explorer: {0}", ex.Message);
            }

            return(false);
        }
コード例 #3
0
        public override bool ShouldPerformTreatment()
        {
            int packageCount = 0;

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismAppxPackageCollection dismAppxPackages = DismApi.GetProvisionedAppxPackages(session);
                    foreach (var package in dismAppxPackages)
                    {
                        if (StoreApps.ShouldRemove(package.DisplayName))
                        {
                            Logger.Log("Would deprovision {0}", package.DisplayName);
                            packageCount += 1;
                        }
                        else
                        {
                            Logger.Log("Not deprovisioning {0}", package.DisplayName);
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }

            if (packageCount > 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public void PerformTreatment()
        {
            int packageCount = 0;

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismAppxPackageCollection dismAppxPackages = DismApi.GetProvisionedAppxPackages(session);
                    foreach (var package in dismAppxPackages)
                    {
                        try
                        {
                            DismApi.RemoveProvisionedAppxPackage(session, package.PackageName);
                            logger.Log("Successfully deprovisioned {0}", package.DisplayName);
                        }
                        catch (DismRebootRequiredException ex)
                        {
                            logger.Log("Successfully deprovisioned {0}: {1}", package.DisplayName, ex.Message);
                        }

                        packageCount += 1;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log("An error occurred while deprovisioning packages: {0}", ex.Message);
            }

            if (packageCount <= 0)
            {
                logger.Log("No Windows Store packages were deprovisioned.");
            }
        }
コード例 #5
0
        public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete)
        {
            if (driverStoreEntry == null)
            {
                throw new ArgumentNullException(nameof(driverStoreEntry));
            }

            switch (this.Type)
            {
            case DriverStoreType.Online:
                return(SetupAPI.DeleteDriver(driverStoreEntry, forceDelete));

            case DriverStoreType.Offline:
                DismApi.Initialize(DismLogLevel.LogErrors);

                try
                {
                    using (DismSession session = this.GetSession())
                    {
                        DismApi.RemoveDriver(session, driverStoreEntry.DriverPublishedName);
                    }
                }
                finally
                {
                    DismApi.Shutdown();
                }

                return(true);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #6
0
        public void CheckImageHealthOnlineSession()
        {
            using (DismSession session = DismApi.OpenOnlineSession())
            {
                DismImageHealthState imageHealthState = DismApi.CheckImageHealth(session, scanImage: false, progressCallback: null, userData: null);

                imageHealthState.ShouldBe(DismImageHealthState.Healthy);
            }
        }
コード例 #7
0
        public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete)
        {
            if (driverStoreEntry == null)
            {
                throw new ArgumentNullException(nameof(driverStoreEntry));
            }

            switch (this.Type)
            {
            case DriverStoreType.Online:
                try
                {
                    SetupAPI.DeleteDriver(driverStoreEntry, forceDelete);
                }
                catch (Win32Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    return(false);
                }

                return(true);

            case DriverStoreType.Offline:
                try
                {
                    DismApi.Initialize(DismLogLevel.LogErrors);

                    try
                    {
                        using (DismSession session = this.GetSession())
                        {
                            DismApi.RemoveDriver(session, driverStoreEntry.DriverPublishedName);
                        }
                    }
                    finally
                    {
                        DismApi.Shutdown();
                    }
                }
                catch (DismRebootRequiredException)
                {
                    return(true);
                }
                catch (DismException ex)
                {
                    Trace.TraceError(ex.ToString());
                    return(false);
                }

                return(true);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #8
0
ファイル: InternetExplorer.cs プロジェクト: jeffxjh/chemo
        public void PerformTreatment()
        {
            string featureName;

            if (Environment.Is64BitOperatingSystem)
            {
                featureName = IE64BitName;
            }
            else
            {
                featureName = IE32BitName;
            }

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismFeatureInfo info = DismApi.GetFeatureInfo(session, featureName);
                    if (
                        info.FeatureState == DismPackageFeatureState.NotPresent ||
                        info.FeatureState == DismPackageFeatureState.Removed ||
                        info.FeatureState == DismPackageFeatureState.Staged)
                    {
                        logger.Log("Internet Explorer 11 is not present on the system.");
                        return;
                    }

                    if (info.FeatureState == DismPackageFeatureState.UninstallPending)
                    {
                        logger.Log("Internet Explorer 11 is already pending uninstall.");
                        return;
                    }

                    try
                    {
                        logger.Log("Disabling Internet Explorer 11...");
                        DismApi.DisableFeature(session, featureName, null, true);
                    }
                    catch (DismRebootRequiredException ex)
                    {
                        logger.Log("Successfully disabled Internet Explorer 11. {0}", ex.Message);
                        return;
                    }

                    logger.Log("Successfully disabled Internet Explorer 11.");
                }
            }
            catch (Exception ex)
            {
                logger.Log("An error occurred while disabling Internet Explorer: {0}", ex.Message);
            }
        }
コード例 #9
0
        public void GetPackageInfoExSimple()
        {
            using (DismSession session = DismApi.OpenOnlineSession())
            {
                DismPackage package = DismApi.GetPackages(session).FirstOrDefault(i => i.PackageState == DismPackageFeatureState.Installed);

                package.ShouldNotBeNull();

                DismPackageInfoEx packageInfoEx = DismApi.GetPackageInfoExByName(session, package.PackageName);

                packageInfoEx.CapabilityId.ShouldNotBeNullOrWhiteSpace();
            }
        }
コード例 #10
0
        public static void SetTargetEdition(string ospath, string edition, ProgressCallback progressCallback)
        {
            int counter = 0;

            //
            // Initialize DISM log
            //
tryagain:
            string tempLog = Path.GetTempFileName();

            DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog);
            DismSession session = DismApi.OpenOfflineSession(ospath);

            try
            {
                void callback3(DismProgress progress)
                {
                    progressCallback?.Invoke(false, (int)Math.Round((double)progress.Current / progress.Total * 100), "Setting edition " + edition);
                }
                DismApi.SetEdition(session, edition, callback3);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed attempt #" + counter);
                Console.WriteLine(ex.ToString());
                //
                // Clean DISM
                //
                DismApi.CloseSession(session);
                try
                {
                    DismApi.Shutdown();
                }
                catch { }
                if (counter < 3)
                {
                    counter++;
                    goto tryagain;
                }
            }

            //
            // Clean DISM
            //
            try
            {
                DismApi.CloseSession(session);
            }
            catch { }
            DismApi.Shutdown();
        }
コード例 #11
0
        public bool AddDriver(string infFullPath, bool install)
        {
            switch (this.Type)
            {
            case DriverStoreType.Online:
                try
                {
                    SetupAPI.AddDriver(infFullPath, install);
                }
                catch (Win32Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    return(false);
                }

                return(true);

            case DriverStoreType.Offline:
                try
                {
                    DismApi.Initialize(DismLogLevel.LogErrors);

                    try
                    {
                        using (DismSession session = this.GetSession())
                        {
                            DismApi.AddDriver(session, infFullPath, false);
                        }
                    }
                    finally
                    {
                        DismApi.Shutdown();
                    }
                }
                catch (DismRebootRequiredException)
                {
                    return(true);
                }
                catch (DismException ex)
                {
                    Trace.TraceError(ex.ToString());
                    return(false);
                }

                return(true);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #12
0
        public List <DriverStoreEntry> EnumeratePackages()
        {
            List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>();

            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = this.GetSession())
                {
                    List <DeviceDriverInfo> driverInfo = this.Type == DriverStoreType.Online
                        ? ConfigManager.GetDeviceDriverInfo()
                        : null;

                    foreach (var driverPackage in DismApi.GetDrivers(session, false))
                    {
                        DriverStoreEntry driverStoreEntry = new DriverStoreEntry
                        {
                            DriverClass          = driverPackage.ClassDescription,
                            DriverInfName        = Path.GetFileName(driverPackage.OriginalFileName),
                            DriverPublishedName  = driverPackage.PublishedName,
                            DriverPkgProvider    = driverPackage.ProviderName,
                            DriverSignerName     = driverPackage.DriverSignature == DismDriverSignature.Signed ? SetupAPI.GetDriverSignerInfo(driverPackage.OriginalFileName) : string.Empty,
                            DriverDate           = driverPackage.Date,
                            DriverVersion        = driverPackage.Version,
                            DriverFolderLocation = Path.GetDirectoryName(driverPackage.OriginalFileName),
                            DriverSize           = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverPackage.OriginalFileName))),
                            BootCritical         = driverPackage.BootCritical,
                            Inbox = driverPackage.InBox,
                        };

                        var deviceInfo = driverInfo?.OrderByDescending(d => d.IsPresent)?.FirstOrDefault(e =>
                                                                                                         string.Equals(Path.GetFileName(e.DriverInf), driverStoreEntry.DriverPublishedName, StringComparison.OrdinalIgnoreCase) &&
                                                                                                         e.DriverVersion == driverStoreEntry.DriverVersion &&
                                                                                                         e.DriverDate == driverStoreEntry.DriverDate);

                        driverStoreEntry.DeviceName    = deviceInfo?.DeviceName;
                        driverStoreEntry.DevicePresent = deviceInfo?.IsPresent;

                        driverStoreEntries.Add(driverStoreEntry);
                    }
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(driverStoreEntries);
        }
コード例 #13
0
        public void GetCapabilitiesOnlineSession()
        {
            using (DismSession session = DismApi.OpenOnlineSession())
            {
                DismCapabilityCollection capabilities = DismApi.GetCapabilities(session);

                capabilities.Count.ShouldBeGreaterThan(0);

                foreach (DismCapability capability in capabilities)
                {
                    capability.Name.ShouldNotBeNullOrWhiteSpace();

                    capability.State.ShouldBeOneOf(DismPackageFeatureState.Installed, DismPackageFeatureState.NotPresent);
                }
            }
        }
コード例 #14
0
        public bool ExportAllDrivers(string destinationPath)
        {
            try
            {
                DismApi.Initialize(DismLogLevel.LogErrors);

                try
                {
                    using (DismSession session = this.GetSession())
                        using (SafeWaitHandle safeWaitHandle = new SafeWaitHandle(IntPtr.Zero, false))
                        {
                            int hresult = NativeMethods._DismExportDriver(session, destinationPath, safeWaitHandle, null, IntPtr.Zero);

                            if (hresult == unchecked ((int)0x80070006))
                            {
                                hresult = NativeMethods._DismExportDriver(session, destinationPath);
                            }

                            if (hresult != 0 && hresult != 1)
                            {
                                string lastErrorMessage = DismApi.GetLastErrorMessage();
                                if (!string.IsNullOrEmpty(lastErrorMessage))
                                {
                                    throw new DismException(lastErrorMessage.Trim());
                                }

                                throw new DismException(hresult);
                            }
                        }
                }
                finally
                {
                    DismApi.Shutdown();
                }
            }
            catch (DismRebootRequiredException)
            {
                return(true);
            }
            catch (DismException ex)
            {
                Trace.TraceError(ex.ToString());
                return(false);
            }

            return(true);
        }
コード例 #15
0
        public override bool PerformTreatment()
        {
            int removedPackageCount = 0;

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismAppxPackageCollection dismAppxPackages = DismApi.GetProvisionedAppxPackages(session);
                    foreach (var package in dismAppxPackages)
                    {
                        try
                        {
                            if (StoreApps.ShouldRemove(package.DisplayName))
                            {
                                DismApi.RemoveProvisionedAppxPackage(session, package.PackageName);
                                Logger.Log("Successfully deprovisioned {0}", package.DisplayName);
                                removedPackageCount += 1;
                            }
                            else
                            {
                                Logger.Log("Not deprovisioning {0}", package.DisplayName);
                            }
                        }
                        catch (DismRebootRequiredException ex)
                        {
                            Logger.Log("Successfully deprovisioned {0}: {1}", package.DisplayName, ex.Message);
                            removedPackageCount += 1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("An error occurred while deprovisioning packages: {0}", ex.Message);
                return(false);
            }

            if (removedPackageCount <= 0)
            {
                Logger.Log("No Windows Store packages were deprovisioned.");
            }

            return(true);
        }
コード例 #16
0
        public bool DeleteDriver(DriverStoreEntry dse, bool forceDelete)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismApi.RemoveDriver(session, dse.DriverFolderLocation);
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(true);
        }
コード例 #17
0
        public bool AddDriver(string infFullPath, bool install)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismApi.AddDriver(session, infFullPath, false);
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(true);
        }
コード例 #18
0
        public bool DeleteDriver(DriverStoreEntry driverStoreEntry, bool forceDelete)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = this.GetSession())
                {
                    DismApi.RemoveDriver(session, driverStoreEntry.DriverPublishedName);
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(true);
        }
コード例 #19
0
        public void GetProvisionedAppxPackagesSimple()
        {
            using (DismSession onlineSession = DismApi.OpenOnlineSession())
            {
                DismAppxPackageCollection packages = DismApi.GetProvisionedAppxPackages(onlineSession);

                packages.ShouldNotBeNull();

                foreach (DismAppxPackage package in packages)
                {
                    package.Architecture.ShouldBeOneOf(Enum.GetValues(typeof(DismProcessorArchitecture)).Cast <DismProcessorArchitecture>().ToArray());
                    package.DisplayName.ShouldNotBeNullOrWhiteSpace();
                    package.InstallLocation.ShouldNotBeNullOrWhiteSpace();
                    package.PackageName.ShouldNotBeNullOrWhiteSpace();
                    package.PublisherId.ShouldNotBeNullOrWhiteSpace();
                    package.ResourceId.ShouldNotBeNullOrWhiteSpace();
                    package.Version.ShouldBeGreaterThan(Version.Parse("0.0.0.0"));
                }
            }
        }
コード例 #20
0
        private async Task <DismSession> GetDismSessionAsync()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(WindowsFeatureManager));
            }

            if (session == null)
            {
                await operatingSystem.ElevateAsync();

                DismApi.Initialize(DismLogLevel.LogErrors);

                session = DismApi.OpenOnlineSessionEx(new DismSessionOptions
                {
                    ThrowExceptionOnRebootRequired = false
                });
            }

            return(session);
        }
コード例 #21
0
ファイル: InternetExplorer.cs プロジェクト: wellswitch/chemo
        public override bool ShouldPerformTreatment()
        {
            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    DismFeatureInfo info = DismApi.GetFeatureInfo(session, resolvedFeatureName);
                    if (
                        info.FeatureState == DismPackageFeatureState.NotPresent ||
                        info.FeatureState == DismPackageFeatureState.Removed ||
                        info.FeatureState == DismPackageFeatureState.Staged ||
                        info.FeatureState == DismPackageFeatureState.UninstallPending)
                    {
                        return(false);
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #22
0
        public void CheckImageHealthOnlineSessionWithCallback()
        {
            const string expectedUserData = "257E41FC307248608E28C3B1F8D5CF09";

            string userData = null;

            int current = -1;
            int total   = -1;

            using (DismSession session = DismApi.OpenOnlineSession())
            {
                try
                {
                    DismApi.CheckImageHealth(
                        session: session,
                        scanImage: true, // Setting scanImage to true seems to trigger the callback being called
                        progressCallback: progress =>
                    {
                        userData = progress.UserData as string;
                        current  = progress.Current;
                        total    = progress.Total;

                        // Cancel the operation, otherwise it takes ~1 min
                        progress.Cancel = true;
                    },
                        userData: expectedUserData);
                }
                catch (OperationCanceledException)
                {
                }

                userData.ShouldBe(expectedUserData);
                current.ShouldBe(50);
                total.ShouldBe(1000);
            }
        }
コード例 #23
0
        public List <DriverStoreEntry> EnumeratePackages()
        {
            List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>();

            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    foreach (var driverPackage in DismApi.GetDrivers(session, false))
                    {
                        driverStoreEntries.Add(new DriverStoreEntry
                        {
                            DriverClass          = driverPackage.ClassDescription,
                            DriverInfName        = Path.GetFileName(driverPackage.OriginalFileName),
                            DriverPublishedName  = driverPackage.PublishedName,
                            DriverPkgProvider    = driverPackage.ProviderName,
                            DriverSignerName     = driverPackage.DriverSignature.ToString(),
                            DriverDate           = driverPackage.Date,
                            DriverVersion        = driverPackage.Version,
                            DriverFolderLocation = Path.GetDirectoryName(driverPackage.OriginalFileName),
                            DriverSize           = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverPackage.OriginalFileName))),
                            BootCritical         = driverPackage.BootCritical,
                            Inbox = driverPackage.InBox,
                        });
                    }
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(driverStoreEntries);
        }
コード例 #24
0
ファイル: Form1.cs プロジェクト: CakeRepository/Friendly-Dism
 private void addDriverMountedButton_Click(object sender, EventArgs e)
 {
     if (driverMountPathTextBox.Text == "PathToDriver" || driverMountPathTextBox.Text == "" || driverMountPathTextBox.Text == null)
     {
         MessageBox.Show("Please Enter PathToDriver");
     }
     else
     {
         DismApi.Initialize(DismLogLevel.LogErrors);
         string driverPath = driverMountPathTextBox.Text;
         Task.Factory.StartNew(() =>
         {
             Task.Run(() =>
             {
                 if (this.InvokeRequired)
                 {
                     this.Invoke((MethodInvoker)(() =>
                     {
                         loadingPanel.Visible = true;
                         mainPanel.Enabled = false;
                         mainPanel.Visible = false;
                     }));
                 }
                 else
                 {
                     loadingPanel.Visible = true;
                     mainPanel.Enabled    = false;
                     mainPanel.Visible    = false;
                 }
             });
             try
             {
                 using (DismSession session = DismApi.OpenOfflineSession(MountPath))
                 {
                     DismApi.AddDriver(session, driverPath, true);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString());
             }
             finally
             {
                 if (this.InvokeRequired)
                 {
                     this.Invoke((MethodInvoker)(() =>
                     {
                         loadingPanel.Visible = false;
                         mainPanel.Enabled = true;
                         mainPanel.Visible = true;
                     }));
                 }
                 else
                 {
                     loadingPanel.Visible = false;
                     mainPanel.Enabled    = true;
                     mainPanel.Visible    = true;
                 }
                 DismApi.Shutdown();
             }
         });
     }
 }
コード例 #25
0
 public static extern int _DismExportDriver(DismSession Session, string Destination);
コード例 #26
0
 public static extern int _DismExportDriver(
     DismSession Session,
     [MarshalAs(UnmanagedType.LPWStr)] string Destination,
     SafeWaitHandle CancelHandle,
     ProgressCallback Progress,
     IntPtr UserData);
コード例 #27
0
ファイル: Form1.cs プロジェクト: CakeRepository/Friendly-Dism
        private void getDriverMountedbutton_Click(object sender, EventArgs e)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);
            Task.Factory.StartNew(() =>
            {
                Task.Run(() =>
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = true;
                            mainPanel.Enabled = false;
                            mainPanel.Visible = false;
                        }));
                    }
                    else
                    {
                        loadingPanel.Visible = true;
                        mainPanel.Enabled    = false;
                        mainPanel.Visible    = false;
                    }
                });
                try
                {
                    using (DismSession session = DismApi.OpenOfflineSession(MountPath))
                    {
                        var drivers = DismApi.GetDrivers(session, true);

                        if (this.InvokeRequired)
                        {
                            this.Invoke((MethodInvoker)(() =>
                            {
                                dismOutputListbox.Items.Add("Driver Information");
                                foreach (var driver in drivers)
                                {
                                    dismOutputListbox.Items.Add("Driver: " + driver.ProviderName + " Version: " + driver.Version);
                                }
                            }));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = false;
                            mainPanel.Enabled = true;
                            mainPanel.Visible = true;
                        }));
                    }
                    else
                    {
                        loadingPanel.Visible = false;
                        mainPanel.Enabled    = true;
                        mainPanel.Visible    = true;
                    }
                    DismApi.Shutdown();
                }
            });
        }
コード例 #28
0
ファイル: Form1.cs プロジェクト: CakeRepository/Friendly-Dism
        private void cleanupOnlineImageButton_Click(object sender, EventArgs e)
        {
            DismApi.Initialize(DismLogLevel.LogErrors);
            Task.Factory.StartNew(() =>
            {
                Task.Run(() =>
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = true;
                            mainPanel.Enabled = false;
                            mainPanel.Visible = false;
                        }));
                    }
                    else
                    {
                        loadingPanel.Visible = true;
                        mainPanel.Enabled    = false;
                        mainPanel.Visible    = false;
                    }
                });


                // Initialize the DismApi



                try
                {
                    List <string> sourcePath = new List <string> {
                        @"C:\"
                    };
                    using (DismSession session = DismApi.OpenOnlineSession())
                    {
                        // Get the features of the image
                        Task.Run(() =>
                        {
                            if (this.InvokeRequired)
                            {
                                this.Invoke((MethodInvoker)(() =>
                                {
                                    label1.Text = "Checking Health";
                                }));
                            }
                        });
                        var health = DismApi.CheckImageHealth(session, false, dismProgress_action);
                        Task.Run(() =>
                        {
                            if (this.InvokeRequired)
                            {
                                this.Invoke((MethodInvoker)(() =>
                                {
                                    label1.Text = "Restoring Health";
                                }));
                            }
                        });
                        DismApi.RestoreImageHealth(session, true, null, dismProgress_action);
                    }
                }
                finally
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            loadingPanel.Visible = false;
                            mainPanel.Enabled = true;
                            mainPanel.Visible = true;
                        }));
                    }
                    else
                    {
                        loadingPanel.Visible = false;
                        mainPanel.Enabled    = true;
                        mainPanel.Visible    = true;
                    }
                    DismApi.Shutdown();
                }
            });
        }