Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get uninstall application path by name issue
Forum Updated to NodeBB v4.3 + New Features

Get uninstall application path by name issue

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.5k Views 2 Watching
  • 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by
    #1

    I want to get application uninstall path by app's name from registry.

    Code:

    QString Test::getAppUninstallPath(QString name)
    {
        QString uninstallLocation;
        QStringList allCurrentUserKeys;
        QSettings registryKeyCurrentUser("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
        allCurrentUserKeys = registryKeyCurrentUser.allKeys();
    
        for (QString key : allCurrentUserKeys) {
            if (key.contains("DisplayName")) {
                if (registryKeyCurrentUser.value(key).toString() == name) {
                    uninstallLocation = registryKeyCurrentUser.value("UninstallString").toString();
                }
            }
        }
    
        return uninstallLocation;
    }
    

    It returns nothing. How to get the app's uninstall path? Thanks.

    C A 2 Replies Last reply
    0
    • Cobra91151C Cobra91151

      I want to get application uninstall path by app's name from registry.

      Code:

      QString Test::getAppUninstallPath(QString name)
      {
          QString uninstallLocation;
          QStringList allCurrentUserKeys;
          QSettings registryKeyCurrentUser("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
          allCurrentUserKeys = registryKeyCurrentUser.allKeys();
      
          for (QString key : allCurrentUserKeys) {
              if (key.contains("DisplayName")) {
                  if (registryKeyCurrentUser.value(key).toString() == name) {
                      uninstallLocation = registryKeyCurrentUser.value("UninstallString").toString();
                  }
              }
          }
      
          return uninstallLocation;
      }
      

      It returns nothing. How to get the app's uninstall path? Thanks.

      C Offline
      C Offline
      Charlie_Hdz
      wrote on last edited by
      #2

      @Cobra91151

      Had you try to debug and see in which part is not working as was expected?

      Thank you.

      Kind Regards,
      Enrique Hernandez
      gearstech.com.mx
      chernandez@gearstech.com.mx

      1 Reply Last reply
      1
      • Cobra91151C Cobra91151

        I want to get application uninstall path by app's name from registry.

        Code:

        QString Test::getAppUninstallPath(QString name)
        {
            QString uninstallLocation;
            QStringList allCurrentUserKeys;
            QSettings registryKeyCurrentUser("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
            allCurrentUserKeys = registryKeyCurrentUser.allKeys();
        
            for (QString key : allCurrentUserKeys) {
                if (key.contains("DisplayName")) {
                    if (registryKeyCurrentUser.value(key).toString() == name) {
                        uninstallLocation = registryKeyCurrentUser.value("UninstallString").toString();
                    }
                }
            }
        
            return uninstallLocation;
        }
        

        It returns nothing. How to get the app's uninstall path? Thanks.

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        @Cobra91151 You need to check each step if you're expecting different behavior.

        I.e. add a check to see if allCurrentUserKeys.isEmpty(). Then add an else for if (key.contains("DisplayName") and finally add an else to the last if (registerKey ...) line.

        In each of those cases just add a qDebug(). Then you can track what is failing which will help you figure out why.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        1
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hi, it's slightly more complicated, because you're dealing with hierarchies/nested keys, so easiest is to use the beginGroup()//endGroup() guys to declutter the code, say like this:

          ...
          QString uninstallLocation;
          QSettings registryKeyLM("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
          
          auto allGroups = registryKeyLM.childGroups();
          for (auto group : allGroups)
          {
              registryKeyLM.beginGroup(group);
          
              for (auto key : registryKeyLM.childKeys())
                  if ("DisplayName" == key)
                      if (registryKeyLM.value(key) == name)
                          uninstallLocation = registryKeyLM.value("UninstallString").toString();
          
              registryKeyLM.endGroup();
          }
          ...
          

          Also, note that in HKEY_CURRENT_USER... you'll only find a handful of entries, the real McCoy you'll find in HKEY_LOCAL_MACHINE.... (on my Windows7 HKCU... contains 3 entries but there are 299 entries in HKLM..) So I changed the code to HKLM...

          Cobra91151C 1 Reply Last reply
          4
          • hskoglundH hskoglund

            Hi, it's slightly more complicated, because you're dealing with hierarchies/nested keys, so easiest is to use the beginGroup()//endGroup() guys to declutter the code, say like this:

            ...
            QString uninstallLocation;
            QSettings registryKeyLM("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
            
            auto allGroups = registryKeyLM.childGroups();
            for (auto group : allGroups)
            {
                registryKeyLM.beginGroup(group);
            
                for (auto key : registryKeyLM.childKeys())
                    if ("DisplayName" == key)
                        if (registryKeyLM.value(key) == name)
                            uninstallLocation = registryKeyLM.value("UninstallString").toString();
            
                registryKeyLM.endGroup();
            }
            ...
            

            Also, note that in HKEY_CURRENT_USER... you'll only find a handful of entries, the real McCoy you'll find in HKEY_LOCAL_MACHINE.... (on my Windows7 HKCU... contains 3 entries but there are 299 entries in HKLM..) So I changed the code to HKLM...

            Cobra91151C Offline
            Cobra91151C Offline
            Cobra91151
            wrote on last edited by
            #5

            @hskoglund

            It works. Thank you.

            A 1 Reply Last reply
            1
            • Cobra91151C Cobra91151

              @hskoglund

              It works. Thank you.

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @Cobra91151 So basically your code worked fine you just didn't have any applications installed for the current user only. That would have been the reason for the test to see if allCurrentUserKeys.isEmpty() was true. :)

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved