?
Solved

Get Printer's List on Windows 2000 (URGENT)

Posted on 2003-03-10
6
Medium Priority
?
1,447 Views
Last Modified: 2013-12-26
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
Comment
Question by:tpadilha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
buasuwan earned 400 total points
ID: 8103951
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
 

Author Comment

by:tpadilha
ID: 8104330
It works on others plataforms as Win9X/Me?
0
 
LVL 5

Expert Comment

by:buasuwan
ID: 8104401
yes, EnumPrinters(..) is a Windows API, It should work on any Win32 version.

It works on my Win98se, XP.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:bluecomet
ID: 8109546
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
 

Author Comment

by:tpadilha
ID: 8109936
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
 

Author Comment

by:tpadilha
ID: 8109941
It quickly solve the question.

Regards,
tpadilha.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question