0

Is it possible to find out the Installation folder of a program, in an eclipse plugin?

For example, there is a program named 'W-app', which is installed at the c:\program files by default. But, some users may select a different directory (eg.D:).

Is it possible to find out what is the installation folder of the 'W-app' program dynamically in java?

greg-449
  • 109,219
  • 232
  • 102
  • 145
Paul-E
  • 91
  • 12

1 Answers1

0

It seems that you're not asking about locating the Eclipse installation itself, but about locating some other program.

In such an event, you have two problems. One, your code will be platform-specific, and two, there is no guaranteed way to do this for arbitrary programs. Based on your post, I am assuming you're interested in Windows.

  • If you know that the program is in the PATH system variable, you can use the where command. where.exe someappinpath.exe will return the path on current Windows versions. To actually execute the command from Java, you can use a simple Runtime.getRuntime().exec() call, or see this question for better ways of doing it.

  • If the program cannot be expected to be in PATH, it is good if you know what it writes to the Windows Registry. Then you could, under HKCU\Software, or under HKLM\Software, possibly locate the application's data and installation location. Again, this requires knowing what the application saves in the Registry.

  • Looking through SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall under both HKCU and HKLM will provide you information about all programs that have written uninstall information. Unfortunately, some programs do not do this, but if that is the case, you cannot really count on anything.

  • As a last resort, you could search the drives for a file matching the program executable's name. This is not a good method, it's slow and you risk finding the wrong file.

From a purely practical perspective, if your plugin relies on some 3rd-party program, I would first try to locate the program automatically (through where or looking up the known Registry key, or the default installation location) and if that fails, ask the user to point out the program's location.

Community
  • 1
  • 1
DUman
  • 2,560
  • 13
  • 16
  • Thanks DUman. This seems to solve my problem. I'll evaluate my possiblities against your solutions, so that what I can do. – Paul-E Mar 04 '15 at 04:02