Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved Write key to windows registry not working

    General and Desktop
    3
    6
    2986
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mjzarrin last edited by SGaist

      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.

      1 Reply Last reply Reply Quote 0
      • hskoglund
        hskoglund last edited by

        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?

        1 Reply Last reply Reply Quote 0
        • M
          mjzarrin last edited by

          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.

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @mjzarrin last edited by

            @mjzarrin said:

            HKEY_CLASSES_ROOT*\shell

            hi
            this might be of interrest to you
            http://stackoverflow.com/questions/25563161/access-to-registry-seems-to-be-different-from-different-sources

            1 Reply Last reply Reply Quote 1
            • hskoglund
              hskoglund last edited by

              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

              1 Reply Last reply Reply Quote 1
              • M
                mjzarrin last edited by

                @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.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post