unit AutorunHlp;
interface
type
TAutorunKind = (akUserRun, akUserRunOnce, akRun, akRunOnce, akRunServices, akRunServicesOnce);
function CreateAutorunEntry(
const AName, AFilename:
String;
const AKind: TAutorunKind): Boolean;
function DeleteAutorunEntry(
const AName:
String;
const AKind: TAutorunKind): Boolean;
implementation
uses Windows, Registry, RegStr;
function GetRegistryPath(
const AKind: TAutorunKind):
string;
begin
case AKind
of
akRun, akUserRun : Result := REGSTR_PATH_RUN;
akRunOnce, akUserRunOnce: Result := REGSTR_PATH_RUNONCE;
akRunServices : Result := REGSTR_PATH_RUNSERVICES;
akRunServicesOnce : Result := REGSTR_PATH_RUNSERVICESONCE;
end;
end;
function CreateAutorunEntry(
const AName, AFilename:
String;
const AKind: TAutorunKind): Boolean;
var
Reg: TRegistry;
begin
Result:=False;
Reg := TRegistry.create;
try
if (AKind=akUserRun)
or (AKind=akUserRunOnce)
then
Reg.Rootkey:= HKEY_CURRENT_USER
else
Reg.RootKey := HKEY_LOCAL_MACHINE;
Result:=Reg.OpenKey(GetRegistryPath(AKind), True);
if AFilename = '
'
then
begin
if Result
then
Result := Reg.DeleteKey(AName);
end
else
Reg.WriteString(AName, AFilename);
finally
Reg.Free;
end;
end;
function DeleteAutorunEntry(
const AName:
String;
const AKind: TAutorunKind): Boolean;
begin
Result := CreateAutorunEntry(AName, '
', AKind);
end;
end.