unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, System.Win.Registry,
Vcl.StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CreateAutorunEntry(
const AName, AFilename:
String; active: Boolean): Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.create;
try
Reg.Rootkey:= HKEY_CURRENT_USER;
Reg.OpenKey('
Software\Microsoft\Windows\CurrentVersion\Run', True);
if active = true
then
Reg.WriteString(AName, AFilename)
else
Reg.DeleteValue(AName);
finally
Reg.Free;
Result := true;
end;
end;
// [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
function IsAutoRun : Boolean;
var Reg : TRegistry;
begin
Reg := TRegistry.create;
try
Reg.Rootkey:= HKEY_CURRENT_USER;
Reg.OpenKey('
Software\Microsoft\Windows\CurrentVersion\Run', True);
// Form1.CheckBox1.Checked :=
Result:= Reg.ValueExists(Application.Title);
finally
Reg.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateAutorunEntry(Application.Title, ParamStr(0), TRUE);
Sleep(1000);
Winapi.Windows.Beep(1000,100);
Winapi.Windows.Beep(2000,100);
CheckBox1.Checked:= IsAutoRun;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CheckBox1.Checked:= IsAutoRun;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
CreateAutorunEntry(Application.Title, ParamStr(0), FALSE);
Sleep(1000);
Winapi.Windows.Beep(2000,100);
Winapi.Windows.Beep(1000,100);
CheckBox1.Checked:= IsAutoRun;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Caption:= Application.Title;
CheckBox1.Checked:= IsAutoRun;
end;
end.