Installer Imprimante Canon Lbp 3010 Page
def is_admin(): """Check if script runs with admin rights (required for printer installation).""" try: return os.getuid() == 0 # Linux/Mac (not used here but safe) except AttributeError: import ctypes return ctypes.windll.shell32.IsUserAnAdmin() != 0
def download_driver(): """Download the official Canon LBP 3010 driver if not present.""" if os.path.exists(DRIVER_FILENAME): print(f"Driver file '{DRIVER_FILENAME}' already exists. Skipping download.") return True
It automates downloading the driver (if missing), installing it silently, and adding the printer via the command line. installer imprimante canon lbp 3010
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
# Check if printer already exists if (Get-Printer -Name $printerName -ErrorAction SilentlyContinue) {{ Write-Host "Printer already exists." }} else {{ # Add printer using existing driver Add-Printer -Name $printerName -DriverName $driverName -PortName $portName Write-Host "Printer added." }} ''' result = subprocess.run(["powershell", "-Command", ps_command], capture_output=True, text=True) if result.returncode != 0: print(f"PowerShell error: {result.stderr}") return False print(result.stdout) return True except Exception as e: print(f"Failed to add printer: {e}") return False def main(): print("=== Canon LBP 3010 Printer Installer ===\n") if platform.system() != "Windows": print("This script is designed for Windows only.") sys.exit(1) def is_admin(): """Check if script runs with admin
# Step 2: Extract if needed (optional) extracted_path = extract_driver_if_needed() if extracted_path: print(f"Driver extracted to {extracted_path}")
""" Canon LBP 3010 Printer Installer (Windows) Automates driver download, silent installation, and printer addition. """ import os import sys import subprocess import platform import urllib.request import zipfile import tempfile import shutil DRIVER_URL = "https://gdlp01.c-wss.com/gds/8/0100005918/01/LBP3010_LBP3018_LBP3050_Driver_V200_W32_en.exe" DRIVER_FILENAME = "LBP3010_Driver.exe" PRINTER_NAME = "Canon LBP3010" PORT_NAME = "USB001" # Most common USB port for this printer Proceeding
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