For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > Re: Is there a way for Windows Service to Read/Write HKCU Reg key









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Is there a way for Windows Service to Read/Write HKCU Reg key
Jochen Kalmbach [MVP]

2005-06-10, 8:59 am

Hi Polaris!

> I'm writing a Windows Service program which needs to read/write the
> HKEY_CURRENT_USER registry key for the current logged on user. I know that
> for a Windows service does not have concept of HKCU since it is always
> running in SYSTEM's context. But is there a way (trick?) for a service to
> access the HKCU registry key?


1. Get a token to an user for example via:
- LogonUser
- OpenProcessToken
- DuplcateToken

2. Use "LoadUserProfile" to load the user-profile.
Then you have the handle to the "HKEY_CURRENT_USER"
registry key in the "PROFILEINFO.Profile" entry
(with KEY_ALL_ACCESS).

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com