Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32: How to use RegisterTypeLib API from standard user

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); 
like image 568
Ian Boyd Avatar asked Nov 12 '08 21:11

Ian Boyd


2 Answers

Take a look at this blog entry I wrote. It will registry ATL COM objects into HKCU instead of HKCR using RegOverridePredefKey. You can use the same technique to call RegisterTypeLib and have it properly register under HKCU

Register ATL as Normal User

like image 115
JaredPar Avatar answered Sep 23 '22 01:09

JaredPar


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
like image 26
Michael Burr Avatar answered Sep 21 '22 01:09

Michael Burr