Win32: How to use RegisterTypeLib API from standard user
security, winapi
Solution
You can use the `RegOverridePredefKey()` API to map the `HKEY_CLASSES_ROOT` regtree to `HKEY_CURRENT_USER\Software\Classes`:
- `http://msdn.microsoft.com/en-us/library/ms724901.aspx`
Problem
The Win32 API call RegisterTypeLib() is used to create the registry keys necessary to register a type library. Unfortunatly, on Windows XP, it tries to write those registry key entries to ``` HKEY_CLASSES_ROOT\TypeLib ``` rather than ``` HKEY_CURRENT_USER\Software\Classes\TypeLib ``` Meaning that a standard user will not be able to run an ActiveX. In May 2008 Microsoft released a hotfix for Vista to correct this issue - but the problem remains on Windows XP. What's a standard-user friendly developer to do? Answer 1 Use the API call that is designed for it: RegisterTypeLibraryForUser() Answer 2 If you can't fix it, hack it: ``` //begin hack HKEY key; RegOpenKeyW(HKEY_CURRENT_USER, @"Software\Classes", out key); RegOverridePredefKey(HKEY_CLASSES_ROOT, key); //do original work RegisterTypeLibrary(...) //stop hacking RegOverridePredefKey(HKEY_CLASSES_ROOT, null); RegCloseKey(key); ```