There are something we should keep in mind when we tried to write a Windows Service. The most important is the “Registry Key”.
In Windows programming, we usually use registry key to setting some value for difference user. Regstry key control become more and more in your code, and we also usually read the specific user in “HKEY_CURRENT_USER” **first then open generic “HKEY_LOCAL_MACHINE” .**
Here comes the problem, According this article(Services and the Registry) in MSDN. We should not use “HKEY_CURRENT_USER” **to retrival current user’s registry key value. Because Windows Services always startup before user login. It may happen some error or loading the wrong setting profile. If you still insist on using the current user registry key setting, please refer ”RegOpenCurrentUser”. In my experience use “RegQueryValueEx” with “HKEY_CURRENT_USER”** will retrival the RootUser’s setting. It make me confuse.
So the better way the use registry key in Windows Service is handle the “HKEY_LOCAL_MACHINE” **rather than “HKEY_CURRENT_USER”.**