0

I am writing a patch for an existing application on Windows using C++. The motive is to edit the configuration file of a software to make it work as per users' requirements.

However, it is important to check whether the software is installed or not before patching it. Moreover, if the software is installed it is important to know in which directory it is installed so that I can open the file in that directory and edit it.

One way was to check if the file exists in "C:\Program Files... etc."

Now, the problem comes when the user has modified the install directory of that software during installation or if it is 64 bit of Windows OS which will instead store it in "C:\Program Files (x86)".

So there is hardly any point of checking presence of file in the default installation directory.

The other way that I have heard some developers do this is by checking Windows registry to know whether the software is installed or not, and in which directory it is installed if it does exists.

Also, I do not know how to look through registry using C++. Neither do I know which registry key or value to check to get the installation path of the software.

Please tell me if there is an alternative to the above two methods that you know of. If there does not exist any good alternative, I would just like to know how can I achieve this goal using registry.

Edit: The software that I'm patching are Dev C++ and Code::Blocks compilers.

Thank you!

Chetan Bhasin
  • 3,503
  • 1
  • 23
  • 36
  • Does the existing "installed" application write the path data to the Windows registry? – TheCodeArtist Aug 14 '13 at 15:32
  • 1
    possible duplicate of [Determine 3rd Party Application Installation Directory](http://stackoverflow.com/questions/1309142/determine-3rd-party-application-installation-directory) – TheCodeArtist Aug 14 '13 at 15:34
  • @TheCodeArtist Let's assume that the software that I'm patching is Dev C++ Compiler which most likely writes the installation path data to Windows registry, if I'm not wrong. – Chetan Bhasin Aug 14 '13 at 15:35
  • If the software is known to save its installation-path in the Windows-registry, then first determine the registry key where it is stored and then checkout this [answer that describes how to read the Windows registry in C++](http://stackoverflow.com/a/35717/319204). – TheCodeArtist Aug 14 '13 at 15:40
  • @TheCodeArtist Alright. I'm checking the answers now. Thanks! – Chetan Bhasin Aug 14 '13 at 15:46
  • You should stop storing configuration files in the same folder as your exe. Use Shell calls in your app startup to find an appropriate place on any system. Any patches can then do the same. – Martin James Aug 14 '13 at 16:52
  • @MartinJames Editing the configuration file was only an example. There are many things that one might need while patching an app. Locating the install directory is, I believe, most important of them. Specially considering a third party application, you don't know what files might be in use for their working. – Chetan Bhasin Aug 14 '13 at 17:32

1 Answers1

0

It is quite hard to answer this because you did not mention the scenarios in which the install directory would be changed. If you are able to change the install directory, why dont you try something like this C:\Program Files (x86)\your_folder_name? This way, your install directory wont be changed by other users.

BudsNanKis
  • 224
  • 5
  • 17
  • Actually that's not the question. See... Usually in Windows applications allow user to specify an install directory before installing them. What if user chooses to install the software in a different drive? Say for example I install all my software in "F:\Install\" – Chetan Bhasin Aug 14 '13 at 15:35