Storing application settings | Registry
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 e开发者_高级运维xist 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.
The LocalService
account can access HKCU\Software\...
See http://msdn.microsoft.com/en-us/library/ms684188%28v=vs.85%29.aspx
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.
精彩评论