uses //加 registry
这是第1步
var reg:tregistry
//定义变量这是第2步
begin //以下是第3步
reg:=tregistry.create
// 创建tregistry对象,为了操作注册表
reg.rootkey:=HKEY_LOCAL_MACHINE
// rootkey指定根键
reg.openkey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true)
// openkey操作主键
reg.WriteString('6331905',application.ExeName )
//实现开机自启动
reg.closekey
//关闭KEY
reg.free
//释放
end;
//下面是实例
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,registry
//加 registry
这是第1步
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
reg:tregistry
//定义变量 , 这是第2步
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageBox (0, '生成成功!'+chr(13)+'生成成功!','千里马网马',64);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin //以下是第3步
reg:=tregistry.create
// 创建tregistry对象,为了操作注册表
reg.rootkey:=HKEY_LOCAL_MACHINE
// rootkey指定根键
reg.openkey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true)
// openkey操作主键
reg.WriteString('6331905',application.ExeName )
//实现开机自启动
reg.closekey
//关闭KEY
reg.free
//释放
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
reg:=tregistry.create
// 创建tregistry对象,为了操作注册表
reg.rootkey:=HKEY_LOCAL_MACHINE
// rootkey指定根键
reg.openkey('SOFTWARE/6331905',true)
// openkey操作主键
reg.writeinteger('7788',0 )
//实现开机自启动
reg.closekey
//关闭KEY
reg.free
//释放
end;
end.
//总结 WriteString 默认RG_SZ writeinteger 默认RG_DWORD