One of our printers is configured on the clients with the IP address as the TCP/IP port to connect to the copier.
However, I would like to create a script that would change the printer port to replace the IP address with a DNS name.
Here's the script I tried, but I'm getting a ton of errors that I'm struggling to resolve:
Code: Select all
import win32print
def modify_printer_port(printer_name, new_port):
printer_handle = win32print.OpenPrinter(printer_name)
printer_info = win32print.GetPrinter(printer_handle, 2)
devmode = printer_info["pDevMode"]
devmode = win32print.DEVMODE(devmode)
devmode.PortName = new_port
win32print.DocumentProperties(0, printer_handle, printer_name, devmode, devmode, 0)
win32print.ClosePrinter(printer_handle)
printer_name = "TOSHIBA4"
new_port = "par-r4accueil-01.imp.fr"
modify_printer_port(printer_name, new_port)THANKS
