BUG: Registry update code may fail when an unprivileged user runs an MFC OLE server on Windows 2000 (254957)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 5.0
- Microsoft Visual C++, 32-bit Editions 6.0
This article was previously published under Q254957 IMPORTANT: This article contains information about modifying the registry. Before you
modify the registry, make sure to back it up and make sure that you understand how to restore
the registry if a problem occurs. For information about how to back up, restore, and edit the
registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986 Description of the Microsoft Windows Registry
SYMPTOMS
When an unprivileged (for example, a non-administrator or a non-power) user runs a standard Microsoft Foundation Classes (MFC) OLE server on Windows 2000,
the registry update fails and displays the following error message:
"Failed to update the system registry. Please try using REGEDIT."
CAUSE
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.
RESOLUTIONWARNING: If you use Registry Editor incorrectly, you may cause serious problems that may
require you to reinstall your operating system. Microsoft cannot guarantee that you can solve
problems that result from using Registry Editor incorrectly. Use Registry Editor at your own
risk.
To resolve the error and allow the server to register when it is executed by a privileged user, test the registry permissions when you open a key, as
demonstrated in the following code:
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
}
Note that the second parameter to RegCreateKeyEx is the document type in the registry. This will be specific to your project.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. REFERENCES
Application Specifications for Microsoft Windows 2000 for Desktop Applications (Specifications\Platforms).
Application Specifications for Microsoft Windows 2000 for Distributed Applications (Specifications\Platforms).
Microsoft Windows 2000 Application Compatibility (Technical Articles\Windows Platform\Windows 2000).
Microsoft Windows 2000 Group Policy (Backgrounders\Windows Platform\Windows 2000)
Modification Type: | Major | Last Reviewed: | 4/28/2005 |
---|
Keywords: | kbtshoot kbBug kbDocView kbOLEApp kbpending KB254957 kbAudDeveloper |
---|
|