Question

I wrote a bunch of unit tests to cover the windows registry reading/writing. They use the CRegKey ATL api.

These worked fine on my desktop machine of XP Pro, but when the tests came to run on the build machine - a Windows 2008 x64 Server - the tests fail with ERROR_ACCESS_DENIED when trying to create a key via Create.

The user who is logged into the build machine belongs to the administrator group.

Google brings up a list of how to create a registry in notepad and msdn keeps giving me missing pages when I click on links.

What I need to know is what I need to do enable the tests to pass when running on the server? I guess it requires security attributes but I have never delved into this so I don't know where to begin. Any help would be appreciated.

Was it helpful?

Solution

The days of programs modifying or creating global registry keys are over and done with. It still works on your XP box because you login as an administrator. Vista, Win7 and Windows 2008 have UAC to prevent anybody (ie malware) messing with the registry, even when logged on with an admin account.

You can add a manifest to your program to invoke the UAC prompt, but that's entirely unpractical for unit tests. Rework your unit test to write to the HKEY_CURRENT_USER hive instead. The same consideration probably applies to the program for which you wrote the tests.

OTHER TIPS

It's not enough to be logged in as an administrator; your program needs to be run with administrative privileges (i.e. using a manifest).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top