It's already been done for you. Take a look at one of the many UDF scripts already pre-written.

http://www.kixtart.org/udf/


EnumPrinterConnections2() - Enumerates all connected printers