Recent

Author Topic: Daemon and Registry  (Read 3284 times)

bambamns

  • Full Member
  • ***
  • Posts: 223
Daemon and Registry
« on: September 24, 2014, 07:56:26 pm »
Hi,

I wrote a daemon (service) and one of options is to access to registry.
Code is in execute part of thread :
Code: [Select]
reg := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
  try
   reg.RootKey := HKEY_CURRENT_USER;
   if reg.OpenKeyReadOnly('\Software\Firebird Backup') then
     Dir := reg.ReadString('path');
  finally
   reg.Free;
  end;                                     

But it wont read a key like it not exist (but it does).

If I copy this code to win32 application it works.

Any clue ?
« Last Edit: September 24, 2014, 08:05:57 pm by bambamns »
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Daemon and Registry
« Reply #1 on: September 25, 2014, 08:18:49 am »
No experience with services but...

My guess is the service doesn't run under the correct user/doesn't have the right permissions/can't even access the CURRENT_USER part of the registry.

IIRC there have been similar posts on the forum before...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

bambamns

  • Full Member
  • ***
  • Posts: 223
Re: Daemon and Registry
« Reply #2 on: September 25, 2014, 10:06:20 pm »
This was my guessing, but the service is installed and started from command line with admin credentials and that was the reason to use OpenKeyReadOnly.

But solution is just to change the rootkey to HKLM , write the values under HKLM you wont yo use and everything works.

I hope it will help someone.
Lazarus 1.8.4 + FPC 2.6.4 x86 (rebuild) and Lazarus 2.0, Windows 7 x64, unless otherwise specified

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Daemon and Registry
« Reply #3 on: September 25, 2014, 11:14:54 pm »
AFAIK, HKCU for a service points to HKEY_USER\.Default. That's probably the reason of your trouble with the first version of your code.

 

TinyPortal © 2005-2018