def restore_bcd(self): backup_path = filedialog.askopenfilename(filetypes=[("BCD files", "*.bcd")]) if backup_path: self.log(f"\n--- Restoring BCD from {backup_path} ---") target = r"C:\Boot\BCD" if not os.path.exists(os.path.dirname(target)): target = r"C:\EFI\Microsoft\Boot\BCD" try: # Need to take ownership/disable protection? Just copy with admin subprocess.run(f'copy /Y "{backup_path}" "{target}"', shell=True, check=True) self.log("✓ Restore successful. Reboot to apply.") except Exception as e: self.log(f"✗ Restore failed: {e}")
self.log("Preparing USB with diskpart...") subprocess.run(f"diskpart /s {dp_script_path}", shell=True, capture_output=True) os.unlink(dp_script_path) winbootmate full
tk.Button(btn_frame, text="1. View Boot Entries", command=self.view_boot_entries, width=20).grid(row=0, column=0, padx=5, pady=5) tk.Button(btn_frame, text="2. Backup BCD", command=self.backup_bcd, width=20).grid(row=0, column=1, padx=5, pady=5) tk.Button(btn_frame, text="3. Restore BCD", command=self.restore_bcd, width=20).grid(row=0, column=2, padx=5, pady=5) def restore_bcd(self): backup_path = filedialog
# Use diskpart + bootsect (common method) with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as dp_script: dp_script.write(f"select volume {usb_drive[0]}\nclean\ncreate partition primary\nactive\nformat fs=ntfs quick\nassign letter={usb_drive[0]}\nexit\n") dp_script_path = dp_script.name View Boot Entries", command=self
self.log("Extracting ISO to USB (this may take a while)...") # Mount ISO mount_result = subprocess.run(f'powershell Mount-DiskImage -ImagePath "{iso_path}" -PassThru', capture_output=True, text=True) if mount_result.returncode != 0: self.log("Failed to mount ISO. Try using Rufus or Ventoy.") return # Get mounted drive letter mount_letter = None for line in mount_result.stdout.splitlines(): if ":" in line and "\\" in line: # crude extraction parts = line.split() for p in parts: if len(p) == 2 and p[1] == ':': mount_letter = p break if not mount_letter: self.log("Could not find mounted ISO drive.") return