Congratulations to our 2022 Qt Champions!

Write key to windows registry not working

  • Hello dear friends
    I am admin user on windows and I need to add my software to Windows context menu.
    I can read registry key but setvalue() function doesn't work.
    this is my code:
    QSettings first(address, QSettings::NativeFormat);
    QString path = first.value("hello").toString();
    qDebug() << "path: " <<path;
    first.setValue("hello", "goodbye");
    QString path2 = first.value("hello").toString();
    qDebug() << "path: " <<path2;
    and this is the result:
    path: "hello"
    path: "hello"

    thank you all.

  • Hi, if you have a registry address set to something like:
    QSettings first("HKEY_CURRENT_USER\\Software\\MyCompany\\TestVariable", QSettings::NativeFormat);
    your code should work fine, but maybe you do not have write access to the place in the registry you want, what's in your variable address?

  • Thank you very much for your reply
    QString address("HKEY_CLASSES_ROOT\*\shell\wipefiles\command");
    QSettings first(address, QSettings::NativeFormat);
    address variable is correctly set and my code can read this. i upload an snapshot from my code here.
    you are right about access permission. i insert Qsettings::status line in my code and it return 1.
    here is said that i have access limitation. how the program can access to registry for write?
    thank you.

  • Lifetime Qt Champion

  • Indeed as @mrjj suggests with the link above, the path HKEY_CLASSES_ROOT does not exist anymore (it was present in Windows 95 but vanished in Windows 2000 and later). To be compatible, Microsoft still allows it, but reroutes it to either HKEY_LOCAL_MACHINE\Software\Classes or HKEY_CURRENT_USER\Software\Classes.

    So perhaps more successful if you try to read/write instead to HKEY_CURRENT_USER\Software\Classes\*\shell\wipefiles\command

  • @mrjj @hskoglund
    thank you very much. i do what you said. i found i cant insert any key value in HKEY_CLASSES_ROOT with qt 5.5 inside Windows 8. so i instead insert my keys and values in HKEY_CURRENT_USER and it worked for bellow addresses.
    for files :"HKEY_CURRENT_USER\Software\Classes\*\shell"
    and for directories : "HKEY_CURRENT_USER\Software\Classes\directory\shell"
    thank you very much for help.

Log in to reply