Installer Imprimante Canon Lbp 3010 !!better!! -

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 add_printer_port(): """Add USB port if not exists (generic USB001 often already exists).""" print(f"Ensuring printer port '{PORT_NAME}' exists...") cmd = f'cscript /nologo %windir%\system32\prnport.vbs -a -r {PORT_NAME} -h 127.0.0.1 -o raw -n 9100' # This is for TCP/IP; for USB, Windows auto-creates on connection. # We'll just rely on USB plug-and-play. If needed, we skip explicit port creation. pass installer imprimante canon lbp 3010

# Step 4: Add printer add_printer_port() if not add_printer(): print("Could not add printer automatically. You may need to add it manually via Control Panel.") def is_admin(): """Check if script runs with admin

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 pass # Step 4: Add printer add_printer_port() if

# Step 3: Install driver if not install_driver(): print("Driver installation failed. Try installing manually.") sys.exit(1)

# Step 2: Extract if needed (optional) extracted_path = extract_driver_if_needed() if extracted_path: print(f"Driver extracted to {extracted_path}")

def add_printer(): """Add printer using Windows printui command.""" print(f"Adding printer '{PRINTER_NAME}'...") try: # Find driver name from inf # Simpler: use printui.dll with /if (install using inf) # We need the driver's INF file. Without INF path, we rely on already installed driver. # Alternative: use PowerShell to add printer using existing driver. ps_command = f''' $driverName = "Canon LBP3010" $printerName = "{PRINTER_NAME}" $portName = "{PORT_NAME}"