• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1448
  • Last Modified:

Get Printer's List on Windows 2000 (URGENT)

How can I get the Windows printer's list on Windows 2000 logged in as any user?

I tried to Get it through Registry, but it didn't bring the printers listed.
0
tpadilha
Asked:
tpadilha
  • 3
  • 2
1 Solution
 
buasuwanCommented:
Hi,

This solution will use Windows API to get all printers name.

1.Declare External Functions
Function boolean EnumPrinters (long flags, long printer_name, long level, ref blob printerinfo, long printerinfo_size, ref long needed_buffer_sizeref, ref long total_printer) Library "winspool.drv" Alias for "EnumPrintersA"
Subroutine GetPrintInfo(ref str_printerinfo printerinfo[], blob data, long data_length) library 'kernel32.dll' Alias for "RtlMoveMemory"
Subroutine GetPrinterName(ref string printername, long data, long data_length) library 'kernel32.dll' Alias for "RtlMoveMemory"

2.new a Structure to get printer infos.

global type str_printerinfo from structure
     long          printername
     long          portname
     long          attributes
     long          devicenotselectedtimeout
     long          transmissionretrytimeout
end type

3.declare Constant
Constant long PRINTER_ENUM_CONNECTIONS = 4
Constant long PRINTER_ENUM_CONTAINER = 32768
Constant long PRINTER_ENUM_DEFAULT = 1
Constant long PRINTER_ENUM_EXPAND = 16384
Constant long PRINTER_ENUM_FAVORITE = 4
Constant long PRINTER_ENUM_ICON1 = 65536
Constant long PRINTER_ENUM_ICON2 = 131072
Constant long PRINTER_ENUM_LOCAL = 2
Constant long PRINTER_ENUM_NAME = 8
Constant long PRINTER_ENUM_NETWORK = 64
Constant long PRINTER_ENUM_REMOTE = 16
Constant long PRINTER_ENUM_SHARED = 32

4.and here is codes

long          ll_index
long           ll_needed_buffer_size
long           ll_total_printer
blob          lb_printerinfo
string     ls_printername[]

// if you want to get default Printer, you have to add  '+ PRINTER_ENUM_DEFAULT' to 2 calling EnumPrinters(...) below.

EnumPrinters (PRINTER_ENUM_CONNECTIONS + PRINTER_ENUM_LOCAL , 0, 5, lb_printerinfo, 0, ll_needed_buffer_size, ll_total_printer)

if ll_needed_buffer_size > 0 then
     lb_printerinfo = blob(space(ll_needed_buffer_size + 200))
     
     if EnumPrinters (PRINTER_ENUM_CONNECTIONS + PRINTER_ENUM_LOCAL , 0, 5, lb_printerinfo, ll_needed_buffer_size, ll_needed_buffer_size, ll_total_printer) then

          str_printerinfo     lstr_printerinfo[]

          for     ll_index = 1 to ll_total_printer
               lstr_printerinfo[ll_index].printername = 0
          next
           
          GetPrintInfo(lstr_printerinfo, lb_printerinfo, 20 * ll_total_printer)

         
          for     ll_index = 1 to ll_total_printer
               ls_printername[ll_index] = space(200)
               GetPrinterName(ls_printername[ll_index], lstr_printerinfo[ll_index].printername, 200)
               ls_printername[ll_index] = trim(ls_printername[ll_index])
          next
         
     end if
end if


0
 
tpadilhaAuthor Commented:
It works on others plataforms as Win9X/Me?
0
 
buasuwanCommented:
yes, EnumPrinters(..) is a Windows API, It should work on any Win32 version.

It works on my Win98se, XP.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
bluecometCommented:
Hi tpadilha,

i don't know which version of PB you have! I have PB 8 and there is a function call printgetprinters() where you get all printers in you system also network printers!

Here are the code i used and put into listbox where user can choose the printer:

ls_listprinter = printgetprinters()
DO WHILE pos (ls_listprinter, "~n" ) <>0
      ll_place=pos (ls_listprinter, "~n" )
      ll_left = Left (ls_listprinter, ll_place - 1)
          lb_2.additem(ll_left)
      ls_listprinter = Mid (ls_listprinter, ll_place + 1)
LOOP
lb_2.additem(ls_listprinter)

hope that helps :)
0
 
tpadilhaAuthor Commented:
Hi bluecomet,

I'm using PB 8.0.3

I already tried to use PrinterGetPrinters and it didn't works correctly. The solution from buasuwan worksand it solve my troubles.

Regards,
tpadilha.
0
 
tpadilhaAuthor Commented:
It quickly solve the question.

Regards,
tpadilha.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now