I'm trying to change registry value, and I receive this error code as result(Error code 1: Incorrect function.).
I receive this error code inside, ModifyValue
as result of RegSetValueEx
. The method is defined in:
utils.h
Could someone help me ?
I have uploaded the code on GitHub: https://github.com/mariopavlov/C/tree/master/RegistryManipulations
Thank you in advance, Mario.
Windows protects these registry values because their change might affect (damage) a lot of applications and subsystems. The code (correctly) attempts to address this problem by taking ownership on the key from system first so that you could break your system up soon afterwards.
Apparently you did not write this code and googled it up somewhere on Internet. The problem there is right in the first of API call in the application:
path = L"SOFTWARE\\Classes\\Interface\\{00020400-0000-0000-C000-000000000046}\\ProxyStubClsid32\\";
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, regsam, &handleToKey))
This fails and you don't have the key opened (because of excessive trailing backslash). You should be checking status of operation against ERROR_SUCCESS
. As the app attempts to use zero handle with followign API calls, you get further errors and your getting 1
there is also incorrect interpretation of API returned code, because you should rather get 6
there (wrong handle).
Having this fixed you will eventually modify the value, however just another reminder here is that it is likely to damage normal operation of quite a number of installed applications.