this slowpoke moves

Create Autostart Entrie

uses Registry

type
  TAutorunKind = (akUserRun,
                  akUserRunOnce,
                  akRun,
                  akRunOnce,
                  akRunServices,
                  akRunServicesOnce);
                
//

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;

   case AKind of
     akRun, akUserRun        : Result:=Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
     akRunOnce, akUserRunOnce: Result:=Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\RunOnce', True);
     akRunServices           : Result:=Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\RunServices', True);
     akRunServicesOnce       : Result:=Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\RunServicesOnce', True);
   end;
   Reg.WriteString(AName, AFilename);
   finally
   Reg.Free;
  end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateAutorunEntry(Application.Title, ParamStr(0), akUserRunOnce);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate