unit BootExec;
interface
uses
Classes,Windows,SysUtils,Registry;
type
TBootExec = class(TComponent)
Private
NombreClave : String;
NombreExec : String;
ProximaVez : Boolean;
Usuario : Boolean;
Protected
Public
constructor Create(AOwner: TComponent); override;
function AppInReg : Boolean;
function AddAppReg : Boolean;
function DelAppReg : Boolean;
Published
Property NombrePrograma : string
Read NombreClave
Write NombreClave;
Property NombreEjecutable : string
Read NombreExec
Write NombreExec;
Property SoloUnaVez : Boolean
Read ProximaVez
Write ProximaVez;
Property SoloUsuario : Boolean
Read Usuario
Write Usuario;
end;
procedure Register;
implementation
constructor TBootExec.Create(AOwner: TComponent);
begin
Inherited;
AddAppReg;
end;
function TBootExec.AppInReg : Boolean;
var
Reg : TRegistry;
RegInfo : TRegDataInfo;
Clave : String;
Valores : TStringList;
I : Integer;
begin
Result:=False; Clave:='Software\Microsoft\Windows\CurrentVersion\Run';
if ProximaVez then Clave := Clave+'Once';
Reg:=TRegistry.Create;
if Not(Usuario) then Reg.RootKey := HKEY_LOCAL_MACHINE;
if Not(Reg.KeyExists(Clave)) Then begin
Reg.Free;
Exit;
end;
Reg.OpenKey(Clave,False); Valores := TStringList.Create;
Reg.GetValueNames(Valores); for I:=0 to (Valores.Count-1) do
begin
if Reg.GetDataInfo( Valores[i], RegInfo) then
begin
if (RegInfo.RegData = rdString) then
begin
if Lowercase(NombreExec)=LowerCase( Reg.ReadString(Valores[i]) ) then
begin
Result:=True;
Break;
end;
end;
end
else
Valores[i]:='';
End; Valores.Free;
Reg.Free;
end;
function TBootExec.AddAppReg : Boolean;
var
Reg : TRegistry;
Clave : string;
begin
Result:=False;
if (NombreClave='') or (NombreExec='') then
Exit;
if AppInReg then
Exit;
Clave:='Software\Microsoft\Windows\CurrentVersion\Run';
if ProximaVez then Clave := Clave+'Once';
Reg:=TRegistry.Create;
if Not(Usuario) then Reg.RootKey := HKEY_LOCAL_MACHINE;
if Not(Reg.KeyExists(Clave)) then
begin
Reg.Free;
Exit;
end;
Reg.OpenKey(Clave,False);
Reg.WriteString(NombreClave,NombreExec);
Reg.Free;
Result:=True;
end;
function TBootExec.DelAppReg : Boolean;
var
Reg : TRegistry;
RegInfo : TRegDataInfo;
Clave : string;
Valores : TStringList;
I : integer;
begin
Result:=False;
if Not(AppInReg) then
Exit;
if (NombreClave='') or (NombreExec='') then
Exit;
Clave:='Software\Microsoft\Windows\CurrentVersion\Run';
if ProximaVez then Clave := Clave+'Once';
Reg:=TRegistry.Create;
if Not(Usuario) then Reg.RootKey := HKEY_LOCAL_MACHINE;
if Not(Reg.KeyExists(Clave)) then
begin
Reg.Free;
Exit;
end;
Reg.OpenKey(Clave,False);
Valores := TStringList.Create;
Reg.GetValueNames(Valores); for I:=0 to (Valores.Count-1) do
begin
if Reg.GetDataInfo( Valores[i], RegInfo) then
begin
if (RegInfo.RegData = rdString) then
begin
if Lowercase(NombreExec)=LowerCase( Reg.ReadString(Valores[i]) ) then
begin
Reg.DeleteValue( Valores[i] );
Result:=True;
end;
end;
end;
end;
Valores.Free;
Reg.Free;
end;
procedure Register;
begin
RegisterComponents('LabGalia', [TBootExec]);
end;
END.