2

I use HKLM\Software\etc\etc to store my basic settings which essentially is the location of my program and it's related database.

The problem I have now is that I have created a Windows Service and need to read those locations. I am unable to read the registry settings as LocalService or LocalSystem which is what the service runs under as HKLM\Software\etc\etc does not of course exist for those user accounts.

Is there a registry Hive that is available to persist that data and is accessible to those services?

It seems I will need to create a text file and store this data somewhere on the file system but before I do, is there any file location that is guaranteed to be the same on everyone's computer. I guess I will need to use a standard environment variable.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
David
  • 958
  • 2
  • 12
  • 29
  • possible duplicate of [Best practice to save application settings in a Windows application](http://stackoverflow.com/questions/453161/best-practice-to-save-application-settings-in-a-windows-application) – John Saunders Jan 27 '11 at 02:41
  • I in fact looked almost everywhere but there was no definitive answer as to where in the registry is a value stored that can be at least read by everyone. – David Jan 27 '11 at 04:26

2 Answers2

1

The LocalService account can access HKCU\Software\...

See http://msdn.microsoft.com/en-us/library/ms684188%28v=vs.85%29.aspx

Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116
  • I just ran a test project and unfortunately the read of the registry did not work although I guess it should have. Let me check it out again...Thanks for the vote, much appreciated. – David Jan 27 '11 at 04:41
0

I know I'm answering my own question, but .............

I honestly don't think it's possible. First of all, the LocalService account opens it's own hive in the HKCU hive and therefor it does not load settings not set for it's own use. As the LocalService is not actually a user account I also doubt whether you can write to it's hive.

I had a look at Impersonation however I have no idea on who to impersonate let alone their password and in any case, impersonating does not load that person's hive.

It's probably possible to search the registry however it is possible that two or more users may be using your program and therefor there is no certainty as to which is which.

The only constant that I can now think of is the %ALLUSERSPROFILE% environment variable and unless someone can come up with another option I will write an xml file there in addition to the registry with the data I need.

David
  • 958
  • 2
  • 12
  • 29