Advice on persisting values for a Windows Service RRS feed

  • Question

  • I am working on an existing C# program which is as a Windows Service. The running service needs to be modified to write (and read) a date value from somewhere but I am finding this quite challenging.  I have tried writing files, using application settings, isolated storage, registry entries but none of these are allowed since the service is defined to use LOCAL SERVICE as the user account for all of the existing installations out there. I do understand that this internal Windows account has very stripped down permissions, which is why I seem to be denied access everytime I try to persist a value somehow.

    So, given that this existing application runs under that account for our current users, I am looking for suggestions for the best way to approach persisting a dateTime variable. Perhaps there is a way to grant a permission to LOCAL SERVICE, or somehow elevate permissions for the write, but I am not overly savvy with managing permissions for built in Windows accounts.  I was really hoping to accomplish this using code so clients could simply upgrade and not need to make permission/account changes, but I am not seeing a way to have this happen. Anyways, any ideas are welcome.

    Thank you for your time.

    Friday, September 7, 2018 7:11 PM


All replies

  • You could use the registry --.


    "The LocalService account has its own subkey under the HKEY_USERS registry key. Therefore, the HKEY_CURRENT_USER registry key is associated with the LocalService account."

    • Marked as answer by Perter Friday, September 7, 2018 7:50 PM
    Friday, September 7, 2018 7:16 PM
  • Thank you! I will try this and report back shortly
    Friday, September 7, 2018 7:32 PM
  • I really appreciate the help and confirmed that this works.  I tried local machine originally which was of course denied. I think I did a quick test for HKCU at one point, but when I checked under HKCU tree, I forgot that I was logged in under a different account so the key wasn't there...note that it can be located under HKEY_USERS. An oversight on my part but glad there is a way to do this.  Thanks again for pointing me in the right direction.
    Friday, September 7, 2018 8:00 PM