views:

31

answers:

2

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.

+1  A: 

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).

Luke
+1  A: 

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.

Hans Passant
No can do. We are creating a product for a 3rd Party and the shared configuration info is stored in HKEY_LOCAL_MACHINE and we are adding our own settings to the pool. I suppose for the testing I could use the current_user instead. The program which we wrote the tests for seem to work fine on the VMs we are testing on, but I haven't tried running the built app on this box.
graham.reeds
Hmya, UAC has a habit of applying the two-by-four to hopes like this. Programs that are recognized as "legacy" and not UAC aware have their registry access redirected. To HKCU.
Hans Passant