delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Finding Printers in the network Format this article printer-friendly!Bookmark function is only available for registered users!
Find printer server for a specific server
Product:
Delphi 5.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
12/16/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet printer printer-server network-printers
Times Scored:
2
Visits:
6896
Uploader: Cleverson Gallego
Company: CONSULT
Reference: N/A
 
Question/Problem/Abstract:
Find the printers for a server specific on the network
Answer:



First: insert on uses the unit name "winspool" and "printers". After this you can write this code using the windows API EnumPrinters: The parameter psName is the server in the network and the result is TStrings. You can use this in a combo or a listbox.

function TForm1.GetPrintServers(psName: string): TStrings;
var
  lpBuffer,lpPrinterInfo: PChar;
  lcCount,lcNumCount : DWord ;
  liCount,liAux:integer;
  lsAuxNome:TStrings;

  function GetContexts ( pctipo : cardinal; ppName : PChar ):TStringlist;
  var
    liCont : integer;
    lsNome:string;
    lbPode:boolean;

  begin
    lbPode:=false;
    Result:=TStringlist.Create;
    case pcTipo of
      8: lbPode :=
        EnumPrinters(pctipo,ppName,1,PByte(lpBuffer),lcCount,lcCount,
          lcNumCount);
      16: lbPode :=
        EnumPrinters(pctipo,nil,1,PByte(lpBuffer),lcCount,lcCount,
          lcNumCount);
    end;
    if not lbPode then
      Exit;
    lpPrinterInfo := lpBuffer;
    for licont := 0 to lcNumCount - 1 do
    begin
      with PPrinterInfo1(lpPrinterInfo)^ do
      begin
        if pcTipo = 8 then
        begin
          liAux:=Pos(',',pDescription);
          lsNome := copy(pDescription,liAux+1,Length(pDescription));
          Result.Add(lsNome);
        end
        else
        begin
          liAux  := Pos(ppName,pName);
          lsNome := copy(pName,liAux,Length(pName));
          if lsNome = ppName then
          begin
            Result.Add(string(pName));
            Exit;
          end;
        end;
      end;
      Inc(lpPrinterInfo, sizeof(TPrinterInfo1));
    end;
  end;
begin
  lsAuxNome:=TStrings.Create;
  lcCount := 0;
  EnumPrinters(PRINTER_ENUM_REMOTE,nil,1,nil,0,lcCount,lcNumCount);
  GetMem(lpBuffer,lcCount);
  lsAuxNome := GetContexts(16,PChar(psName));
  if lsAuxNome.Count <> 0   then
    Result:=GetContexts(8,PChar(lsAuxNome.Strings[0]))
  else
  begin
    lsAuxNome.Add('Não Encontrada');
    Result:=lsAuxNome;
  end;
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Not fetching printers which are under the system
    Japhar Ali (Apr 18 2007 10:31AM)

Hi,
I built a new project with the code which you have written.
Code is working fine and fetching only the system names in the network not the printers names which are available under the system.

For Ex: My network is having the below printers which are under the Systems.

System1
   printer1
   printer2
System2
   printer3
   printer4

As per the code it is fetching only the System1, System2 not the printers under the system.

Actually my requirement is, i want the system name as well as the printer names.

Can you please help me how to get the Printer names under the systems in the network?

Respond

network with a router
    Omer Can (Jun 6 2006 9:18PM)

Hi

Can I use your function as I have a quite simple
network with two computers and a router
(Windows XP Prof with Delphi 7 and
cable-internewt)?

What to set for Server?

Thanks

Respond

RE: network with a router
Uzekena Hipopotam (Dec 2 2006 12:30PM)

These are very long. You can use the Registry for printers and short codes.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
S. Kucherov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)