uses Registry;
function StartButtonKontextEintrag(prog, prog_name: string; setzen: boolean):
boolean;
var
Reg: TRegistry;
s: string;
begin
result := false;
Reg := TRegistry.Create;
s := '\Directory\shell\' + stringreplace(prog_name, '&', '', []);
try
Reg.RootKey := HKEY_CLASSES_ROOT;
if setzen then begin
if Reg.OpenKey(s, True) then begin
Reg.writestring('', prog_name);
Reg.CloseKey;
end;
if Reg.OpenKey(s + '\Command', True) then begin
Reg.writestring('', prog);
result := true;
end else Reg.deletekey(s);
end else begin
Reg.deletekey(s);
result := true;
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;
// Beispielaufruf zum setzen eines Eintrags
procedure TForm1.Button12Click(Sender: TObject);
begin
if not
StartButtonKontextEintrag('c:\windows\calc.exe', '&Taschenrechner', true)
then showmessage('FEHLER');
end;