Using C++ to edit the registry

Solution 1:

  • Open the registry : RegOpenKeyEx

  • Query the value : RegQueryValueEx

    /* do something with value*/

  • Set the value back : RegSetValueEx

  • close the registry : RegCloseKey

Solution 2:

Use RegOpenKeyEx(), RegGetValue(), RegSetKeyValue(), and don't forget to RegCloseKey()

Here's a link to the reference: http://msdn.microsoft.com/en-us/library/ms724875(VS.85).aspx

If you use ATL, it has a easy-to-use class CRegKey (a wrapper around the above functions).

Solution 3:

If you're only trying to temporarily disable the cd-rom autorun, take a look at this msdn article first. Actually, look at it first before disabling it permanently anyway. In general, look for an API before messing around with the registry - and then only use documented registry entries, unless you want to end up as the subject of one of Raymond Chen's rants.