delphi这段代码什么意思

来源:百度知道 编辑:UC知道 时间:2024/06/20 15:34:15
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,
/

把程序的 标题和绝对路径写到 注册表'Software\Microsoft\Windows\CurrentVersion\Run'健下.

同意楼上
另还有功能:一个程序在一台电脑上只能运行一次