Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to fetch Program files in Windows
QtWS25 Last Chance

How to fetch Program files in Windows

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
program fileswindows
4 Posts 4 Posters 652 Views
  • 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.
  • S Offline
    S Offline
    supratik123
    wrote on last edited by
    #1

    I am developing an application which has to copy certain folders in the Program Files location where the application will be installed. I have looked into QStandardPaths but unable to find any variable for Program files in windows. Looking into forum and googling always gives me ApplicationLocation or data location which are not C/D:Program Files.

    getenv is also deprecated which doesnt serve the purpose. Can we somehow fetch Program files in Windows using variable?

    SGaistS Paul ColbyP 2 Replies Last reply
    0
    • S supratik123

      I am developing an application which has to copy certain folders in the Program Files location where the application will be installed. I have looked into QStandardPaths but unable to find any variable for Program files in windows. Looking into forum and googling always gives me ApplicationLocation or data location which are not C/D:Program Files.

      getenv is also deprecated which doesnt serve the purpose. Can we somehow fetch Program files in Windows using variable?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you explain why you need to copy these files ?

      In any case, doesn't QCoreApplication::applicationDirPath do what you want ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S supratik123

        I am developing an application which has to copy certain folders in the Program Files location where the application will be installed. I have looked into QStandardPaths but unable to find any variable for Program files in windows. Looking into forum and googling always gives me ApplicationLocation or data location which are not C/D:Program Files.

        getenv is also deprecated which doesnt serve the purpose. Can we somehow fetch Program files in Windows using variable?

        Paul ColbyP Offline
        Paul ColbyP Offline
        Paul Colby
        wrote on last edited by
        #3

        Hi @supratik123,

        Looking into forum and googling always gives me ApplicationLocation or data location which are not C/D:Program Files.

        That is correct. As per the docs, ApplicationsLocation will yield something like "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs" on Windows (which is a bit odd, if you ask me). And the *DataLocation will be user data paths, not "Program Files".

        getenv is also deprecated which doesnt serve the purpose.

        Actually, getenv() is only deprecated because that ancient version not threadsafe, and returns a pointer to table entry should not be modified. There's nothing wrong with reading the programfiles (and programfiles(86)) environment variables, its just strongly recommended (and for good reason) that you use something safer, eg getenv_s() or _wgetenv_s() on Windows, or secure_getenv() on Linux.

        Personally, I would use Qt's qgetenv() or qEnvironmentVariable() functions, which, on Windows, wrap getenv_s() and _wgetenv_s() respectively. You can see how they do it here: qtenvironmentvariables.cpp.

        Cheers.

        JonBJ 1 Reply Last reply
        1
        • Paul ColbyP Paul Colby

          Hi @supratik123,

          Looking into forum and googling always gives me ApplicationLocation or data location which are not C/D:Program Files.

          That is correct. As per the docs, ApplicationsLocation will yield something like "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs" on Windows (which is a bit odd, if you ask me). And the *DataLocation will be user data paths, not "Program Files".

          getenv is also deprecated which doesnt serve the purpose.

          Actually, getenv() is only deprecated because that ancient version not threadsafe, and returns a pointer to table entry should not be modified. There's nothing wrong with reading the programfiles (and programfiles(86)) environment variables, its just strongly recommended (and for good reason) that you use something safer, eg getenv_s() or _wgetenv_s() on Windows, or secure_getenv() on Linux.

          Personally, I would use Qt's qgetenv() or qEnvironmentVariable() functions, which, on Windows, wrap getenv_s() and _wgetenv_s() respectively. You can see how they do it here: qtenvironmentvariables.cpp.

          Cheers.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Paul-Colby
          As you say, ApplicationsLocation returning .../Start Menu/Programs seems a bit "odd". It is "surprising" that Qt does not offer anything to return Program Files etc. under Windows. Yes, these are very Windows-specific, and Qt is largely (but not totally) platform-agnostic, but still I would have guessed Qt would offer something for this. But it is what it is, and code can use environment variables or native Windows calls to get the desired path.

          @supratik123
          Don't forget to verify whether you are looking for Program Files or Program Files (x86), they are not the same place!

          1 Reply Last reply
          1

          • Login

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