Python script to install network printers
future_retro at yahoo.co.uk
future_retro at yahoo.co.uk
Wed Oct 5 05:50:53 EDT 2005
These functions should get you started and probably finished...
def createprinterport(IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
printerport = WBEM.Get("Win32_TCPIPPrinterPort").SpawnInstance_()
printerport.Properties_('Name').Value = 'IP_'+IPAddress
printerport.Properties_('Protocol').Value = 1
printerport.Properties_('HostAddress').Value = IPAddress
printerport.Properties_('PortNumber').Value = '9100'
printerport.Properties_('SNMPEnabled').Value = 'False'
printerport.Put_()
def
createprinter(PrinterName,DriverName,Location,ShareName,IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.ImpersonationLevel = 3
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
printer = WBEM.Get("Win32_Printer").SpawnInstance_()
printer.Properties_('DeviceID').Value = PrinterName
printer.Properties_('DriverName').Value = DriverName
printer.Properties_('Location').Value = Location
printer.Properties_('Network').Value = 'True'
printer.Properties_('Shared').Value = 'True'
printer.Properties_('ShareName').Value = ShareName
printer.Properties_('PortName').Value = 'IP_'+IPAddress
printer.Put_()
I also created one for migrating print drivers but had loads of
problems with it. If the driver doesn't pass Microsoft logo testing
the scripts fail even if it is signed by Microsoft. I never worked out
why there were 2 levels of protection.
More information about the Python-list
mailing list