简体   繁体   English

如何在Java eclipse插件中找到程序的安装文件夹

[英]How to find out the installation folder of a program in Java eclipse plugin

Is it possible to find out the Installation folder of a program, in an eclipse plugin? 是否有可能在eclipse插件中找到程序的Installation文件夹?

For example, there is a program named 'W-app', which is installed at the c:\\program files by default. 例如,有一个名为“W-app”的程序,默认情况下安装在c:\\ program文件中。 But, some users may select a different directory (eg.D:). 但是,一些用户可能会选择不同的目录(例如D :)。

Is it possible to find out what is the installation folder of the 'W-app' program dynamically in java? 是否有可能在java中动态找出'W-app'程序的安装文件夹?

It seems that you're not asking about locating the Eclipse installation itself, but about locating some other program. 您似乎并不是要求查找Eclipse安装本身,而是要查找其他程序。

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. 根据您的帖子,我假设您对Windows感兴趣。

  • If you know that the program is in the PATH system variable, you can use the where command. 如果您知道程序在PATH系统变量中,则可以使用where命令。 where.exe someappinpath.exe will return the path on current Windows versions. where.exe someappinpath.exe将返回当前Windows版本的路径。 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. 要从Java实际执行命令,您可以使用简单的Runtime.getRuntime().exec()调用,或者查看此问题以获得更好的方法。

  • If the program cannot be expected to be in PATH, it is good if you know what it writes to the Windows Registry. 如果程序不能在PATH中,那么如果你知道它写入Windows注册表的内容是很好的。 Then you could, under HKCU\\Software , or under HKLM\\Software , possibly locate the application's data and installation location. 然后,您可以在HKCU\\SoftwareHKLM\\Software下找到应用程序的数据和安装位置。 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. HKCUHKLMSOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall将为您提供有关已编写卸载信息的所有程序的信息。 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. 从纯粹实用的角度来看,如果你的插件依赖于某些第三方程序,我会首先尝试自动定位程序(通过where或查找已知的注册表项或默认安装位置),如果失败,请询问用户指出程序的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM