Python script to install network printers

M

Matt Chan

Hi, I am trying to create a python script to install a set of network
printers. I have had success using an os.popen statement, using
rundll32 and printui.dll. This takes way too long. Can someone point
me in a quicker direction?

thanks,
Matt
 
R

Roger Upole

You can use win32print.AddPrinterConnection(r'\\server\sharedprinter').
However, if the printer driver has to be copied to the client machine and
installed, that's probably where most of the time is spent.
hth
Roger

Hi, I am trying to create a python script to install a set of network
printers. I have had success using an os.popen statement, using
rundll32 and printui.dll. This takes way too long. Can someone point
me in a quicker direction?

thanks,
Matt
 
F

future_retro

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top