Registering COM Components, and Windows 7 Permissions Weirdness
Tuesday, May 12th, 2009I’ve been fiddling with COM components lately, trying to set up a simple server application that allows late binding so that I can call the API from languages other than C/C++, but I soon ran into an interesting permissions problem when trying to register the object for the second time (don’t ask): RegCreateKeyEx in my DllRegisterServer() function was returning ERROR_ACCESS_DENIED (5) even though I was running an account with administrative rights. I found this rather puzzling, and the worst part was that regsvr32.exe returned with a misleading success message.

After some Googling, I ran across an article which suggested that I change the permissions of the HKCR and HKCR\CLSID registry keys. I eventually did this, explicitly enabling full control to both them and their sub-keys for all users, but with no success. The solution, I eventually found, was to launch Visual Studio itself in administrative mode, which did the trick (maybe this should have been my first step, but hey, my account is an admin account!).


After all this, it seems to me that registering a COM component shouldn’t require administrative access; at the very least, it would be nice if I just had to confirm the registry change — which I would like to think User Account Control would be capable of discerning. Also, because I didn’t have any sort of problem registering the component for the first time (I was running Vista at the time), I kind of wonder if this is a Windows 7 RC fluke or just an intentional permissions lock-down on the new-and-improved version of UAC.
Update: Disabling UAC completely also allowed the component to register.

A quick tip on the side (not my own): Note that I have VS set up to use regsvr32.exe to “run” the debug profile so that the code can be debugged within the IDE. To do this, open the properties page for your COM server project, click on the debugging section, enter “regsvr32.exe” into the Command box, and “”$(TargetPath)”" into Command Arguments (you need one pair of quotes for the latter).



