Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a Service app in C 5 years ago for Windows XP. I am now porting it to Windows 7. This app writes to the registry under HKLM\Software\mycompanyname\myappname.

If I watch that registry key while the service is running I do not see any values getting updated when I hit F5 to refresh the registry view. I know some of these values are written to during start up. But if I stop the service, and do a refresh on that Registry key, I then see the updated values.

It is as if the service has that registry key locked for reading until it stops. So it makes me wonder if my apps that use this service can read the current values from the registry while the service is running??

In XP this works normally. If I regularly hit F5 to refresh the registry key view all values that have changed are updated while the service is still running.

Is this expected behavior, and if so, why??
Posted

Writing to the registry requires admin privileges. You probably have to install it from the admin account on the machine.
 
Share this answer
 
It does write to the Registry. It is just that nothing shows up in the Registry until I stop it. It runs under the LOCAL SYSTEM context but I have also tried running it under the administrator account and it makes no difference.

If I run the same executable standalone, not as a service, it behaves properly.
 
Share this answer
 
Please check the return value of RegCreateKeyEx or RegSetValueEx. If it is not ERROR_SUCCESS than find the error message with the help of FormatMessage.
Here is the code to find the error message ->[^] :)
 
Share this answer
 
Ok, you're going to love this....

Since the service won't display messages (because it does not support interactive user on Win7) I have to write errors to a log file, which I started doing last week when I first started porting over to Win7.

I should have mentioned this earlier, but my output log file does not get created until I stop the service, just like the Registry entries don't get written until I stop the service. And RegSetValueEx is returning ERROR_SUCCCESS.
 
Share this answer
 
Comments
ShilpiP 15-Nov-10 13:56pm    
I dont think so ... i had created a service and i am able to see the logs when service is running on windows 7, vista.
Is this a 32-bit app running on 64-bit Windows???

If so, you'll want to open RegEdit and look under HKLM\Software\Wow6432Node\... then down to your apps key.

I suspect the reson you're seeing it show up after the app closes is because of Registry Reflection[^].
 
Share this answer
 
Comments
chiselca 15-Nov-10 14:37pm    
Dave, Yes, it IS a 32 bit app, but see my further explanations below regarding 32 bit and 64 bit Windows. And yes, I am aware, but only recently, about the Wow6432Node registry key. On my x64 machine that node is not getting updated until the service is stopped.
I share your disbelief but I see this behavior with my own two eyes.

I have been doing most of my testing on a Windows 7 Ultimate x86 VM under Virtual PC with my Windows XP machine acting as host.

My actual target machine is running Windows 7 Professional x64. When I started having so many issues with this service on that machine I switched over to my VM since it is easier to debug on and it is 32 bit. Also, my x64 machine is subject to corporate security policies which cause problems of their own and my VM is a plain vanilla install of Win7.

The log files behave the same way on the Win 7 x64 machine as they do on my VM, they don't get created until I stop the service. Likewise with the Registry entries, they don't appear in the Registry until I stop the service.

I realize these behaviors are pretty hard to believe but I have proven it on two totally different and independent environments. My app ran fine in Windows XP for 5 years.
 
Share this answer
 
Comments
Dave Kreskowiak 15-Nov-10 18:58pm    
What I mean by looking in the Registry is that your service may be updating keys in one location in the registry and you're looking with RegEdit in the other. Sync hasn't gotten around to updating the keys yet, so you don't see any changes.
Dave Kreskowiak 15-Nov-10 18:59pm    
Does your service keep the registry keys open for the life of the service?? If so, that's probably why your not seeing the changes sync up. Reflection only happens when RegCloseKey (Win32 API) is called.
chiselca 16-Nov-10 6:58am    
On the 64 bit machine I am watching my service's registry keys under the "WOW6432Node". They don't update until the service is stopped. Likewise, on the 32 bit VM I monitor my keys under "HKLM\Software" and they also do not update until the service is stopped. Where else could the service possibly be writing to? On Windows XP the registry keys are updated immediately while the service is running. Also, with regards to 'Reflection', from what I have read Reflection is disabled in Windows 7.

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