Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wanna access some subkey under HKEY_CLASSES_ROOT in my atl windows service.
the msdn says below:

"A service should not access HKEY_CURRENT_USER or HKEY_CLASSES_ROOT, especially when impersonating a user. Instead, use the RegOpenCurrentUser or RegOpenUserClassesRoot function.

If you attempt to access HKEY_CURRENT_USER or HKEY_CLASSES_ROOT from a service it may fail, or it may appear to work but there is an underlying leak that can lead to problems loading or unloading the user profile.
"

So I use OpenProcessToken() to get token of the process, then call RegOpenUserClassesRoot() to try to get access to the HKEY_CLASSES_ROOT key. But the call fails with error 0x00000002, says "system cannot find the specified file".

anyone got any idea why this call fails? and how i can access HKEY_CLASSES_ROOT in my atl service?

thanks.
Posted

1 solution

How about using HKLM\software\classes as a pseudonym for HKCR ?

I wasn't aware there was a potential problem accessing the HKCR from services; I have services that are continually battering away at HKLM
 
Share this answer
 
Comments
ericchan1336 2-Aug-11 22:47pm    
sorry barneyman HKCR is the only key I wanna access to.
barneyman 2-Aug-11 23:41pm    
HKLM\software\classes == HKCR
ericchan1336 3-Aug-11 5:13am    
no no no it's not what you say

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900