Autimation - Is MS recommended fix for "Failed to update the system registry..." flawed?

  • Thread starter Thread starter Al Koch
  • Start date Start date
A

Al Koch

Hello,
I have an automation server that, when run under W2000 and XP as a User
without Admin privileges, causes the error message "Failed to update the
system registry. Please try using REGEDIT." I discovered KB 254957 that
explains that this is a bug in W2000 (and apparently is still in XP!) and
provides a workaround. This error is generated in a VC++ 6 AppWizard
generated app with Automation support in which in the app's InitInstance()
makes the following call which was automatically generated by the Wizard:

m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);

Here is an excerpt from KB 254957:

This error occurs because each time an MFC OLE executable server runs, it
calls the UpdateRegistry function in the COleTemplateServer class. The MFC
UpdateRegistry function updates the registry entries in HKEY_CLASSES_ROOT
for both the application and its document types. This update either creates
the entries when the program is executed for the first time, or updates the
entries to repair any damage that may have occurred. In Windows 2000, access
to HKEY_CLASSES_ROOT is restricted to administrators and power users

and the recommended workaround is simply:

HKEY hTestKey = NULL;

LONG lResult = ::RegCreateKeyEx(HKEY_CLASSES_ROOT,

"MFCOServ.Document", 0, "",

REG_OPTION_NON_VOLATILE,

KEY_ALL_ACCESS, NULL,

&hTestKey, NULL);

if ((ERROR_SUCCESS == lResult) && (hTestKey != NULL))

{

// It's ok to call UpdateRegistry

}

This workaround just allows the code to avoid doing the call to
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT); which does eliminate the error
message. However, it raises the question of what happens if an application
is installed (by an Admin) but the 1st User to run it is not an Admin. In
this case we won't do the UpdateRegistry() that, as I understand it,
*Registers the automation server*! Is the workaround flawed or is there
something that allows this to work in this circumstance?

Thank you.

Al Koch
 
Back
Top