forked from HemulGM/Components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHGM.Autorun.pas
95 lines (82 loc) · 2.31 KB
/
HGM.Autorun.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
unit HGM.Autorun;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Registry;
type
TAutorun = class
private
FAppName, FAppCommand: string;
function GetAutorunCurrentReg: Boolean;
procedure SetAutorunCurrentReg(const Value: Boolean);
function GetAutorunLocalReg: Boolean;
procedure SetAutorunLocalReg(const Value: Boolean);
public
constructor Create(AppName, AppCommand: string);
property AppName: string read FAppName write FAppName;
property AppCommand: string read FAppCommand write FAppCommand;
property AutorunCurrentReg: Boolean read GetAutorunCurrentReg write SetAutorunCurrentReg;
property AutorunLocalReg: Boolean read GetAutorunLocalReg write SetAutorunLocalReg;
end;
implementation
{ TAutorun }
constructor TAutorun.Create(AppName, AppCommand: string);
begin
FAppName := AppName;
FAppCommand := AppCommand;
end;
function TAutorun.GetAutorunCurrentReg: Boolean;
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(KEY_READ);
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Run\') then
begin
Result := Reg.ValueExists(FAppName);
end
else
begin
Reg.Free;
raise Exception.Create('Îøèáêà ïðè ÷òåíèè äàííûõ èç ðååñòðà');
end;
Reg.Free;
end;
procedure TAutorun.SetAutorunCurrentReg(const Value: Boolean);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion', True);
Reg.WriteString('Run', FAppName, FAppCommand);
Reg.Free;
end;
function TAutorun.GetAutorunLocalReg: Boolean;
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(KEY_READ);
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Run\') then
begin
Result := Reg.ValueExists(FAppName);
end
else
begin
Reg.Free;
raise Exception.Create('Îøèáêà ïðè ÷òåíèè äàííûõ èç ðååñòðà');
end;
Reg.Free;
end;
procedure TAutorun.SetAutorunLocalReg(const Value: Boolean);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(KEY_WRITE);
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion', True);
Reg.WriteString('Run', FAppName, FAppCommand);
Reg.Free;
end;
end.