Arsip: Cara mendapatkan printer pada suatu komputer (di jaringan yang di share tentunya


by kaka-delphi in Networking more 14 years ago 2062
Pertama: masukkan unit Winspool dan Printers pada klausa Uses.
Parameter psName adalah nama komputer di jaringan dan di simpan di TStrings.
Kita dapat menggunakan Combo atau ListBox.
Berikut cuplikan source code nya :
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('Printer tidak ditemukan');
Result:=lsAuxNome;
end;
end;
Syntax Highlighted with https://pascal-id.org/syntax
Contoh penggunaan nya, tambakan komponen TButton dan TListBox. Pada event OnClick TButton, sisipkan kode berikut :
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items:= GetPrintServers(Edit1.Text);
end;
Syntax Highlighted with https://pascal-id.org/syntax


berikut skrinsyutnya :


Untuk contoh project, dapat di download di PulicFolder dengan nama ScanPrinter.rar
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com