[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8192
  • Last Modified:

How to fix 'Failed to update registry. Please try using REGEDIT.'

Hi,

I am getting the above warning on Windows 2000 machine if any user tries to lauch the program installed by the administrator. I know this is a documented bug and a work aroud is to give the user write permission to the specific regsitry keys. But what I want is to be able to do it programatically. I need to know if there are any APIs for doing this. The program was developed in Visual C++ 6.0 and uses COM DCOM. I have noted that the warning is flagged when UpdateRegistry is called in the InitInstance(). Please help.

Best regards,
Abhijeet Joshi
0
Abhimj
Asked:
Abhimj
  • 6
  • 5
  • 3
  • +1
1 Solution
 
rcarlanCommented:

I don't think the problem qualifies as a bug. Your application tries to write to sections of the Registry that the user running the program doesn't have permission to write to.

There are two obvious solutions:
1) Update your installation utility to give all users running the program write access permission to the corresponding Registry sections, or
2) Make sure your program doesn't try to write to (or otherwise access) Registry sections for which the user running the program doesn't have corresponding access permissions.

If the call to UpdateRegistry that you are referring to is to register your COM server(s), you shouldn't call the method every time your program runs. It is normally called only when the program is invoked with the -regserver command. This should only happen during installation (which is normally performed by an administrator).

To set the access permissions on a Registry key you should call RegSetKeySecurity.

Radu
0
 
Julian HansenCommented:
Some more information on what your app is doing would be useful.
0
 
AbhimjAuthor Commented:
rcarlan, yes I came across this on a site. But couldnt find the function name in the devstudio to do this. Any help on this one?

julianH, i think you fogot to paste the link?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Julian HansenCommented:
No - I was asking for more information not providing it.
0
 
AbhimjAuthor Commented:
julianH, oops sorry :)
If the software is installed by an administrator, it runs ok, but if it is run by some other user (a resricted, non admin, non previkedged user), that warning message is displayed, once clikced on OK, the software runs as usual, without any problems.
0
 
Julian HansenCommented:
What is the application trying to do at the point when the error message is being displayed?

If it is loading a COM object then the problem may be there - in which case do you have source for the COM object?

We had a similar problem with a client a while back - turns out a product they had bought had a COM component that, due to bad programming practice, was trying to create a key in the HKEY_CLASSES_ROOT hive every time it ran. Because normal users where restricted from writing to this part of the registry they got an error. The proposed solution was to give the users write access to the specific key (or even the whole of classes root). This is not the correct solution. The correct solution (the one we eventually enforced) was the developer had to change the code in the COM object.

It is bad programming practice to attempt to access restricted portions of the machine during the normal running of an application (unless of course it is an administration app). The only time an app should do this is during install - which would be a once off under an admin account.

Bottom line - app should not attempt to access restricted portions of registry / file system during normal running of app - solution - fix problem component so that it does not do this.

0
 
rcarlanCommented:
>>rcarlan, yes I came across this on a site. But couldnt find the function name in the devstudio to do this. Any help on this one?

If you are referring to a function to set the access permissions, I've already mentioned it in my previous message: RegSetKeySecurity. Of course, you can only call it under an admin account (e.g. during installation).

Radu
0
 
AbhimjAuthor Commented:
rcarlan - RegSetKeySecurity is not an Installshield API. I wanted to know if theres a way of setting the registry key values during installation. I came across a variable ALLUSERS in the install shield help. Know anything more about it?

julianH - my app is not registering any components when it is run. The function UpdateRegistry is called in the InitInstance(). That call was generated by the app wizardd when the app was created. I will paste it here for your referance:
 
      // When a server application is launched stand-alone, it is a good idea
      //  to update the system registry in case it has been damaged.
      m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
      COleObjectFactory::UpdateRegistryAll();

Is it ok to comment the call out?
0
 
rcarlanCommented:

Your code should only call these methods when the application is invoked with /RegServer (if an exe) or in the DllRegisterServer function (if a DLL).

Also, make sure you unregister your COM server if invoked with /UnregServer (or in DLLUnregisterServer) - i.e. call UpdateRegistryAll(FALSE).

RegSetKeySecurity is not an InstallShield API, it is a Windows API. Anyway, now that it's clear that you were talking about self registration of a COM server, you wouldn't want to change the Registry permissions for the corresponding keys anyway (they are under HKCR, APID, CLSID, etc...).

Radu
0
 
AbhimjAuthor Commented:
rcarlan - sorry i should have told this earlier, but the code which i had pasted is a container which included automation support. The exe is not te be run with /Regserver. Again, the above call was inserted by the appwizard itself.
0
 
rcarlanCommented:
>>The exe is not te be run with /Regserver

Why?
0
 
AbhimjAuthor Commented:
Because its a stand alone exe and not a in-proc component or anything. If you want to replicate it, create a application in mfc appwizard and jus tadd the automation support. You will see that the call has been inserted by the framework itself. I am new to COM programming so cannot really what UpdateRegistry does, or why should it be called every time the app starts.
0
 
rcarlanCommented:
A stand-alone COM server should register itself with the OS when called with /RegServer and unregister when called with /UnregServer.
An in-proc COM server gets registered through regsvr32. For this, it needs to export DllRegisterServer and DllUnregisterServer.

Don't take the Wizard's results/output as the final solution. It's just a starting point. It gets you going but it doesn't deliver you to the destination. Don't be afraid to change code generated by the Wizard. At the same time, though, you need to know what you're doing :-)

You should not register you COM server every time the app starts. The Wizard comment:

     // When a server application is launched stand-alone, it is a good idea
     //  to update the system registry in case it has been damaged.

is bollocks. It may have been "a good idea" in Windows 95, but it's a very bad idea in NT4/W2K/XP because of user permissions.

The only time a local (or remote) COM server should register is when called with /RegServer.

Radu
0
 
rcarlanCommented:
I believe I've answered the question.

Radu
0
 
ravikumarchCommented:
Just set the program to run in compatibility mode..
and if possible set the option to run the program as an administrator..
This solved the problem for me.. :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now