I don't know wheres my mistake. It always jumps to the else branch, but the key exist, I checked it several times.
var
reg : TRegistry;
begin
with TRegistry.Create do try
RootKey:=HKEY_CURRENT_USER;
OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', False);
if KeyExists('nginx.exe') then begin
ShowMessage('Ja geht ist da');
Result := True;
btnAutostart.ImageIndex := 5
end
else begin
Result := False;
btnAutostart.ImageIndex := 0;
end;
finally
Free;
end;
end;
You need to call ValueExists rather than KeyExists. A key is what appears as a folder in Regedit but you are looking for a value named nginx.exe in the key HKCU\Software\...\Run.
Some other comments:
OpenKeyReadOnly rather than OpenKey.OpenKeyReadOnly in case the key cannot be opened.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With