Author Topic: Retrieving a list of mapped network printers and their paths  (Read 1430 times)

0 Members and 1 Guest are viewing this topic.

psuchewinner

  • Guest
Retrieving a list of mapped network printers and their paths
« on: September 18, 2008, 09:45:16 AM »
Ok,
Hopefully this will be easy for someone but I can not figure out how do retrieve a list of of printers and their associated paths from my computer.  Our printers here are on a network and I would like to be able to populate a list box with the names of the printers that are available (or are mapped) on a users computer.  I am thinking of something like that which appears in the "Printer/Plotter" area of the create a new pagesetup dialog.  Can anyone help? 

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Retrieving a list of mapped network printers and their paths
« Reply #1 on: September 18, 2008, 09:53:00 AM »
Code: [Select]
(defun _GetNetworkPrinters ( / WshNetwork oPrinters result i )

    ;;  2007/12/xx Michael Puckett
    ;;
    ;;  Translated from http://tinyurl.com/2496ow
    ;;
    ;;  typical result --
    ;;
    ;;  (
    ;;      ("PDFFILE:"       . "Win2PDF")
    ;;      ("XPSPort:"       . "Microsoft XPS Document Writer")
    ;;      ("IP_nn.n.nn.nnn" . "\\\\server\\Plotter Name 1")
    ;;      ...
    ;;      ("IP_nn.n.nn.nnn" . "\\\\server\\Plotter Name n")
    ;;  )
    ;;

    (setq
        WshNetwork (vlax-create-object "WScript.Network")
        oPrinters  (vlax-invoke WshNetwork 'EnumPrinterConnections)
    )
   
    ;;  weird, count is a method, not a property of oPrinters
   
    (repeat (setq i (vlax-invoke oPrinters 'Count))
   
        (if (zerop (rem (setq i (1- i)) 2))
            (setq result
                (cons
                    (cons
                        ;;  weird, item is a method,
                        ;;  not a property of oPrinters
                        (vlax-invoke
                            oPrinters
                           'Item
                            i
                        )
                        (vlax-invoke
                            oPrinters
                           'Item
                            (1+ i)
                        )
                    )   
                    result
                )           
            )
        )
   
    )
   
    (vlax-release-object oPrinters)
   
    (vlax-release-object WshNetwork)
   
    result
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

psuchewinner

  • Guest
Re: Retrieving a list of mapped network printers and their paths
« Reply #2 on: September 18, 2008, 10:48:28 AM »
Perfect, EXACTLY what I was looking for!
Thank you.......Thank you very much.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Retrieving a list of mapped network printers and their paths
« Reply #3 on: September 18, 2008, 01:08:16 PM »
Perfect, EXACTLY what I was looking for!
Thank you.......Thank you very much.

Yes, very nice!
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Retrieving a list of mapped network printers and their paths
« Reply #4 on: September 18, 2008, 01:50:16 PM »
Thanks guys and you're most welcome.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst