Installer Imprimante Canon Lbp 3010 |work| -
def install_driver(): """Silently install the Canon driver.""" print("Installing driver (this may take a few minutes)...") try: # Silent install: /S for NSIS installers, /quiet for MSI # Common Canon driver installer flags: /S /v/qn result = subprocess.run( [DRIVER_FILENAME, "/S", "/v/qn"], capture_output=True, text=True, timeout=120 ) if result.returncode != 0: print(f"Installation returned code {result.returncode}") print("Stdout:", result.stdout) print("Stderr:", result.stderr) return False print("Driver installed successfully.") return True except subprocess.TimeoutExpired: print("Installation timed out but may still succeed. Proceeding...") return True except Exception as e: print(f"Installation failed: {e}") return False
print(f"Downloading driver from {DRIVER_URL}...") try: urllib.request.urlretrieve(DRIVER_URL, DRIVER_FILENAME) print("Download complete.") return True except Exception as e: print(f"Download failed: {e}") print("Please download manually from Canon support and place it in the same folder as this script.") return False def extract_driver_if_needed(): """Some Canon .exe files are self-extracting ZIPs. Extract if needed.""" # For simplicity, if it's an exe, we'll run it silently later. # But we check if it's a known self-extractor by magic bytes. with open(DRIVER_FILENAME, "rb") as f: header = f.read(4) if header == b'PK\x03\x04': # ZIP file print("Detected ZIP archive. Extracting...") with zipfile.ZipFile(DRIVER_FILENAME, 'r') as zip_ref: extract_path = tempfile.mkdtemp() zip_ref.extractall(extract_path) # Look for an installer (.exe or .msi) for root, dirs, files in os.walk(extract_path): for file in files: if file.lower().endswith(('.exe', '.msi')): new_path = os.path.join(os.getcwd(), "extracted_driver") shutil.copytree(extract_path, new_path, dirs_exist_ok=True) print(f"Extracted to {new_path}") return new_path return None installer imprimante canon lbp 3010
# Step 1: Download driver if not download_driver(): sys.exit(1) def install_driver(): """Silently install the Canon driver