镁合金化学镀镍:Delphi获取所有打印机名称和型号

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 23:12:49

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Registry, StdCtrls;

type
TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;
const MAX_PATH = 144;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var R: TRegistry;
i: integer;
L: TstringList;
S: string;
begin
R := TRegistry.Create;
L := TStringList.Create;
S := '\System\CurrentControlSet\Control\Print\Printers';
R.RootKey := HKEY_LOCAL_MACHINE;
R.OpenKey(S,false);
R.GetKeyNames(L);// 得到子键名列表
R.CloseKey;
ListBox1.Items.Clear;
for i := 0 to L.Count - 1 Do
begin
    R.OpenKey(S + '\' + L[i], false);
    ListBox1.Items.Add(R.ReadString('Name')+' '+ R.ReadString('Printer Driver') );
    //列出打印机的名字 和型号
    R.CloseKey;
end;
R.Free;
L.Free;
end;


end.