'If using NT use PRINTER_INFO_4 and %PRINTER_ENUM_CONNECTIONS
Code:
#DIM ALL 'Place all printer names in PRINTERS.INI #REGISTER NONE #COMPILE EXE $INCLUDE "win32api.inc" FUNCTION IsWin95() EXPORT AS LONG LOCAL vi AS OSVERSIONINFO vi.dwOsVersionInfoSize = SIZEOF(vi) GetVersionEx vi FUNCTION = (vi.dwPlatformId = %VER_PLATFORM_WIN32_WINDOWS) END FUNCTION FUNCTION GetPrinterNames() AS STRING DIM Level AS LONG DIM Needed AS LONG DIM Returned AS LONG DIM Element AS LONG DIM EntireString AS STRING IF IsWin95 THEN Level = 5 ELSE Level = 4 'Printer structure to use IF Level = 5 THEN 'First call to see how big WINDOWS 95 printer_info_5 structure CALL EnumPrinters(%PRINTER_ENUM_LOCAL, _ BYVAL 0, _ BYVAL Level, _ BYVAL %NULL, _ BYVAL 0, _ needed&, _ 'Size of structure in bytes returned&) DIM PI5(0) AS PRINTER_INFO_5 REDIM PI5(needed& \ SIZEOF(PI5(0))) CALL EnumPrinters(%PRINTER_ENUM_LOCAL, _ BYVAL 0, _ BYVAL Level, _ BYVAL VARPTR(PI5(0)), _ needed&, _ needed&, _ returned&) 'Number of printers FOR Element = 0 TO Returned& - 1 EntireString = EntireString + PI5(Element)[email protected]+"," NEXT ERASE PI5 ELSE ' Windows NT 'First call to see how big WINDOWS NT printer_info_4 structure CALL EnumPrinters(%PRINTER_ENUM_CONNECTIONS, _ BYVAL 0, _ BYVAL Level, _ BYVAL %NULL, _ BYVAL 0, _ needed&, _ 'Size of structure returned in needed& returned&) DIM PI4(0) AS PRINTER_INFO_4 REDIM PI4(needed& \ SIZEOF(PI4(0))) CALL EnumPrinters(%PRINTER_ENUM_CONNECTIONS, _ 'Use CONNECTIONS with NT BYVAL 0, _ BYVAL Level, _ BYVAL VARPTR(PI4(0)), _ needed&, _ needed&, _ returned&) 'Number of printers FOR Element = 0 TO Returned& - 1 EntireString = EntireString + PI4(Element)[email protected]+"," NEXT ERASE PI4 END IF GetPrinterNames = LEFT$(EntireString,LEN(EntireString)-1) END FUNCTION FUNCTION PBMAIN () AS LONG DIM PrinterNames AS STRING 'Will hold returned printer names DIM Count AS LONG 'Count number of printer names DIM Org AS LONG DIM EachPrinter AS STRING PrinterNames = GetPrinterNames() 'Assign printer names from function Count = PARSECOUNT(PrinterNames) 'Number of concatenated printer names IF count THEN OPEN "PRINTERS.INI" FOR OUTPUT AS #1 FOR org = 1 TO Count EachPrinter = PARSE$(PrinterNames$,Org) PRINT #1,EachPrinter 'comma separated printer names 'PRINT EachPrinter NEXT CLOSE #1 END IF 'WAITKEY$ END FUNCTION
------------------
Leave a comment: