LEXMARK PRINTER SETUP
=====================

Sets up a Lexmark printer on a Windows PC as one printer per paper tray
(e.g. "Lexmark MS823dn - Tray 1", "Lexmark MS823dn - Tray 2"), each one
already set to print from its own tray. It finds the printer on the network
by itself, so nobody needs to know its IP address.


FOR PHARMACY STAFF
------------------
1. Right-click the zip file and choose "Extract All". Don't run it from
   inside the zip.
2. Open the extracted folder and double-click Setup-Printers.bat.
   - If Windows shows a security warning, choose Run (or "More info", then
     "Run anyway").
   - Click Yes when Windows asks to allow changes.
3. Pick from the menu:

   1) Find a Lexmark and set up its trays
      First-time setup, or to redo a printer from scratch.
   2) Fix a printer that can't be found
      Use this when a Lexmark shows Offline, "Status unavailable", or jobs
      sit in the queue. It finds the printer again and reconnects every
      tray printer to it.
   3) Print test pages
      Each tray printer prints a page. Check it came out of the right tray.
   4) Remove printers

If something goes wrong, send support the newest file in
C:\ProgramData\LexmarkSetup


FOR WHOEVER MAINTAINS THIS TOOL
-------------------------------
The Lexmark Universal v2 XL driver is already in drivers\Universal
(drivers\Universal\ABOUT THIS DRIVER.txt says where it came from). To
replace it with a newer one:

  1. From Lexmark's support site, download the printer software package
     for the MS823 (one .exe, about 200 MB).
  2. Open it with 7-Zip and take InstallationPackage\Drivers\x64\print64XL.msi.
  3. Unpack that without installing it:
       msiexec /a print64XL.msi /qn TARGETDIR=C:\some\empty\folder
  4. Replace the contents of drivers\Universal with everything in
     C:\some\empty\folder\Lexmark\Lexmark Universal v2 XL\Drivers\Print\GDI
  5. Zip the whole LexmarkPrinterSetup folder (right-click, Send to,
     Compressed (zipped) folder) and upload the zip.

Check that Lexmark's license lets you share their driver on a public page.
If it doesn't, keep the download link private.

Choosing a driver per model: drivers\drivers.csv

  ModelPattern,Folder,DriverName
  ^MS8,Universal,
  .*,Universal,

  ModelPattern is matched against the model the printer reports (e.g.
  MS823dn); the first matching row wins. Folder is a folder under drivers\.
  DriverName is optional: blank uses the best name in that folder's .inf
  files (PCL XL first, PostScript last). To use a model-specific driver for
  some printers, put it in drivers\<NewFolder>\ and add a row above ".*".

How it works

  - Finding printers: checks every address on the PC's network for the
    printing port (9100), then asks each one what it is over SNMP (model,
    serial number, installed trays). If SNMP is off, it reads the model
    from the printer's web page and takes the tray list from the driver.
  - It also asks printers to announce themselves, the same way Windows'
    own printer search does. That finds printers outside the PC's address
    range, like one stuck on a 169.254.x.x address because the network
    never gave it one. The tool says when that's the case: it can still set
    the printer up on that address, but the real fix is getting the printer
    an address from whoever runs the network.
  - Each Windows printer connects straight to the printer's IP address.
    It doesn't use the Windows "Add a printer" search, which is what
    produces "Status unavailable".
  - Every printer it creates has "LexmarkSetup serial=... tray=..." in its
    Comment. Option 2 uses the serial to find the same printer at a new
    address after its IP changes.
  - The permanent fix for printers that keep changing address is a
    reserved IP for the printer in the pharmacy's router.

Requirements: Windows 10 or 11, an administrator account (or the admin
password), and the PC on the same network as the printer.

Not yet tried on a real Lexmark. The first time you run it on one, check:
  - option 1 lists the printer with its model and serial, and its trays;
  - each tray printer's test page comes out of the tray in its name.
If a tray is wrong or a tray printer reports it couldn't set the tray, the
log in C:\ProgramData\LexmarkSetup lists the driver's paper-source names.
