unit Unit1;

interface

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

type
TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);

private

    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure SetAutorun(aProgTitle,aCmdLine: string; aRunOnce: boolean );
var
hKey: string;
hReg: TRegIniFile;
begin
if aRunOnce then
//程序只自动运行一次
    hKey := 'Once'
else
    hKey := '';
hReg := TRegIniFile.Create('');
//TregIniFile类的对象需要创建
hReg.RootKey := HKEY_LOCAL_MACHINE;
//设置根键
hReg.WriteString('Software\Microsoft\Windows\CurrentVersion\Run'
                  + hKey + #0,
                  aProgTitle,
                  //程序名称,可以为自定义值
                  aCmdLine );
                  //命令行数据,必须为该程序的绝对路径+程序完整名称
hReg.destroy;
//释放创建的hReg
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
   SetAutorun(Application.Title,application.ExeName,false);

end;

end.

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2021-04-26
  • 2022-12-23
  • 2021-12-03
  • 2021-11-23
  • 2021-09-17
  • 2022-01-17
猜你喜欢
  • 2021-11-23
  • 2022-01-23
  • 2021-11-30
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案