public static void SetProductKey(string ospath, string productkey) { // // Initialize DISM log // string tempLog = Path.GetTempFileName(); DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog); var session = DismApi.OpenOfflineSession(ospath); try { DismApi.SetProductKey(session, productkey); } finally //(Exception ex) { } // // Clean DISM // DismApi.CloseSession(session); DismApi.Shutdown(); File.Delete(tempLog); }
public static string GetCurrentEdition(string ospath) { // // Initialize DISM log // string tempLog = Path.GetTempFileName(); DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog); var session = DismApi.OpenOfflineSession(ospath); string edition = null; try { edition = DismApi.GetCurrentEdition(session); } finally //(Exception ex) { } // // Clean DISM // DismApi.CloseSession(session); DismApi.Shutdown(); File.Delete(tempLog); return(edition); }
private DismSession GetSession() { foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages()) { DismApi.UnmountImage(mountedImageInfo.MountPath, false); } DismApi.CleanupMountpoints(); DismApi.MountImage(InstallWimPath, MountPath, 1); return(DismApi.OpenOfflineSession(MountPath)); }
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(); }
private DismSession GetSession() { switch (this.Type) { case DriverStoreType.Online: return(DismApi.OpenOnlineSession()); case DriverStoreType.Offline: return(DismApi.OpenOfflineSession(this.OfflineStoreLocation)); default: throw new NotSupportedException(); } }
public static void UninstallPEComponents(string ospath, ProgressCallback progressCallback) { // // Initialize DISM log // string tempLog = Path.GetTempFileName(); DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog); var session = DismApi.OpenOfflineSession(ospath); var packages = DismApi.GetPackages(session); List <DismPackage> componentsToRemove = new List <DismPackage>(); // // Queue components we don't need according to our hardcoded list for removal // foreach (var package in packages) { if (componentsNotInWinPE.Any(x => package.PackageName.StartsWith(x, StringComparison.InvariantCultureIgnoreCase))) { componentsToRemove.Add(package); } } // // Remove components // foreach (var pkg in componentsToRemove) { try { void callback3(DismProgress progress) { progressCallback?.Invoke(false, (int)Math.Round((double)progress.Current / progress.Total * 100), "Removing " + pkg.PackageName); } DismApi.RemovePackageByName(session, pkg.PackageName, callback3); } catch //(Exception ex) { } } // // Clean DISM // DismApi.CloseSession(session); DismApi.Shutdown(); File.Delete(tempLog); }
public static void ApplyUnattend(string ospath, string unattendpath) { bool ok = false; while (!ok) { try { // // Initialize DISM log // string tempLog = Path.GetTempFileName(); DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog); var session = DismApi.OpenOfflineSession(ospath); try { DismApi.ApplyUnattend(session, unattendpath, true); } finally //(Exception ex) { } // // Clean DISM // DismApi.CloseSession(session); DismApi.Shutdown(); File.Delete(tempLog); ok = true; } catch (Exception ex) { Console.WriteLine("Failed applying unattend, retrying in one second..."); Console.WriteLine(ex.ToString()); ok = false; Thread.Sleep(1000); } } }
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(); } }); }
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(); } }); } }