Python script to install network printers

Discussion in 'Python' started by Matt Chan, Oct 4, 2005.

  1. Matt Chan

    Matt Chan Guest

    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
     
    Matt Chan, Oct 4, 2005
    #1
    1. Advertising

  2. Matt Chan

    Roger Upole Guest

    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

    "Matt Chan" <> wrote in message news:...
    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 =---
     
    Roger Upole, Oct 5, 2005
    #2
    1. Advertising

  3. Matt Chan

    Guest

    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.
     
    , Oct 5, 2005
    #3
  4. Matt Chan

    Guest

    The target OS needs to support WMI so 2000 or XP.
     
    , Oct 5, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dexter

    How to list network printers?

    Dexter, Jan 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    433
    Dexter
    Jan 7, 2005
  2. Replies:
    0
    Views:
    507
  3. Replies:
    0
    Views:
    628
  4. Replies:
    0
    Views:
    381
  5. Ornette

    Finding Network Printers

    Ornette, Apr 1, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    328
    Ornette
    Apr 1, 2007
Loading...

Share This Page