Hello!
I'm writing Windows Service, that will check few registry keys.
Is there any possibility to read registry keys from HKEY_Curren_User, when
.NET Application is running in Local System context?
HKEY_CURRENT_USER is separate, individual, different for each user account.
How would your service know what account's HKCU to use?
The simple answer: if your service has to access HKCU it must run under the
account of the user who's HKCU you want to access, not under local system.
You can circumvent that by loading and unloading registry hives yourself,
but that's something I definitely would NOT recommend.
It's *very* easy to lose a user's complete profile (everything in his HKCU
and in his "Documents and Settings" subtree), by having that account's HKCU
hive loaded when the system doesn't expect it.
Try it out with a test account:
WARNING: THERE IS NO WAY TO UNDO THE DAMAGE.
Start regedit (or regedt32 under w2k), position yourself on the HKEY_USERS
root, File --> Load Hive, browse to the user.dat file of a user that isn't
logged on at the moment and load it.
The file is located in his \Documents and Settings\Username directory.
Now close regedit (regedt32) without unloading that hive, log off, and log
on as the user who's hive you just loaded: the system forgets all it knew
about that user, and creates a whole new subdirectory for it under
\Documents and Settings.