Python script to install network printers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Chan

    #1

    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
  • Roger Upole

    #2
    Re: Python script to install network printers

    You can use win32print.AddP rinterConnectio n(r'\\server\sh aredprinter').
    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" <engineuity@gma il.com> wrote in message news:mailman.14 46.1128439429.5 09.python-list@python.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 =---

    Comment

    • future_retro@yahoo.co.uk

      #3
      Re: Python script to install network printers

      These functions should get you started and probably finished...

      def createprinterpo rt(IPAddress,Se rverName):
      WBEM =
      win32com.client .GetObject(r"wi nmgmts:{imperso nationLevel=imp ersonate}!\\"
      + ServerName + r"\root\cimv 2")
      WBEM.Security_. Privileges.AddA sString("SeLoad DriverPrivilege ")
      printerport = WBEM.Get("Win32 _TCPIPPrinterPo rt").SpawnInsta nce_()
      printerport.Pro perties_('Name' ).Value = 'IP_'+IPAddress
      printerport.Pro perties_('Proto col').Value = 1
      printerport.Pro perties_('HostA ddress').Value = IPAddress
      printerport.Pro perties_('PortN umber').Value = '9100'
      printerport.Pro perties_('SNMPE nabled').Value = 'False'
      printerport.Put _()

      def
      createprinter(P rinterName,Driv erName,Location ,ShareName,IPAd dress,ServerNam e):
      WBEM =
      win32com.client .GetObject(r"wi nmgmts:{imperso nationLevel=imp ersonate}!\\"
      + ServerName + r"\root\cimv 2")
      WBEM.Security_. ImpersonationLe vel = 3
      WBEM.Security_. Privileges.AddA sString("SeLoad DriverPrivilege ")
      printer = WBEM.Get("Win32 _Printer").Spaw nInstance_()
      printer.Propert ies_('DeviceID' ).Value = PrinterName
      printer.Propert ies_('DriverNam e').Value = DriverName
      printer.Propert ies_('Location' ).Value = Location
      printer.Propert ies_('Network') .Value = 'True'
      printer.Propert ies_('Shared'). Value = 'True'
      printer.Propert ies_('ShareName ').Value = ShareName
      printer.Propert ies_('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.

      Comment

      • future_retro@yahoo.co.uk

        #4
        Re: Python script to install network printers

        The target OS needs to support WMI so 2000 or XP.

        Comment

        Working...