title: How to access HKCU registry of currently logged on user(s), from a service?
body: <p>From within a windows service I want to check some user preferences that are stored within each users' HKCU registry area. How can I do this?</p>
  
  <p>I see that HKEY_USERS has subkeys of each user that has logged in to the machine (or something like that?), and within these are the HKCU areas for each user. However, these subkeys are the SIDs of the users, so somehow I'd need to work out the SID of the currently logged in user(s).</p>
  
  <p>I would then query <code>HKEY_USERS\&lt;the users SID&gt;\whichever\key\i\need</code> in place of querying <code>HKEY_CURRENT_USER\whichever\key\i\need</code>.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/2077958/how-to-determine-the-current-windows-user-from-a-windows-service">this question</a> I can get a list of the current users on the machine in DOMAIN\USER format. Is there a way to get the SID of a user from their windows login? Or is there a more direct way to get the registry path that is HKCU for the currently logged in user(s)?</p>