473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Python script to install network printers

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
Oct 4 '05 #1
3 6741
You can use win32print.AddPrinterConnection(r'\\server\sharedp rinter').
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

"Matt Chan" <en********@gmail.com> wrote in message news:ma*************************************@pytho n.org...
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


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Oct 4 '05 #2
These functions should get you started and probably finished...

def createprinterport(IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonatio nLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDrive rPrivilege")
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,Shar eName,IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonatio nLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.ImpersonationLevel = 3
WBEM.Security_.Privileges.AddAsString("SeLoadDrive rPrivilege")
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.

Oct 5 '05 #3
The target OS needs to support WMI so 2000 or XP.

Oct 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: dcrespo | last post by:
Hi all... Is there a way to print a PDF file directly from Python without having Acrobat installed? I know about ReportLab. It's a python module that lets you create almost any PDF document, but I...
23
by: anton.vredegoor | last post by:
Here's my situation: I'm typing this in a public library on a computer with OS windows 2000 server. I can run Internet explorer, word, excel and powerpoint, that's it. Maybe java, but it seems...
0
by: Sneid | last post by:
Hi I explain my title: i'm actually developping an application for privilege-limited users. They all have a laptop, and are not local administrators of the machine I 'm developping a program...
0
by: Martijn | last post by:
Hi, I created an application that installs network printers. Everything seems to work oke...but the printer is not set to default. I use the following line to install the printer ...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
5
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
0
by: Python Nutter | last post by:
Mini install guide for python on the iPhone: Cydia =Install SSH helps make initial configuration easier until you get used to MobileTerminal Cydia =Install MobileTerminal (closest to a bash...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.