如何向 Java 应用程序的 Windows 资源管理器添加上下文菜单?

发布于 2024-07-09 15:51:28 字数 66 浏览 5 评论 0原文

如何为 Java 应用程序添加一个子菜单项到 Windows 资源管理器上下文菜单(例如 7-Zip 就是这样做的)?

How would one go about adding a submenu item to the windows explorer context menu (like for example 7-Zip does) for a Java application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡渣熟男 2024-07-16 15:51:28

我知道有两种方法可以做到这一点。 最奇特的方法是编写一个 Windows shell 扩展,我相信 powerarchiver、winzip 等就是这样做的(这涉及运行代码来确定上下文菜单项将依赖于所选文件)。

对于简单的功能,简单的方法是您可以在注册表中添加一个条目:

HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command

其中 是此上下文菜单应适用的文件,即 *、.mdb、.doc

您想要在上下文菜单中显示的内容。

然后将默认字符串添加为要从上下文菜单启动的应用程序的路径,并且您可以使用 %1 来引用当前选定的文件,即我使用的 MS Access:

HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"

然后为任何文件添加一个上下文菜单项我选择(因此是 *),这允许我在 MS Access 2000 中启动它。

当然,在破解注册表之前一定要备份它。

您的程序可以在安装期间或首次运行时执行此操作。

I am aware of two ways to do it. The fancy way is to write a windows shell extension, which is how powerarchiver, winzip etc do it I believe (this involves running code to determine what the context menu items will be dependent on the file chosen).

The simple way, for simple functionality, is you can add an entry in the registry :

HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command

Where <file type> is the files that this context menu should apply to i.e. *, .mdb, .doc

and

<display text> what you want to show in the context menu.

Then add the default string as a path to the application you want to launch from the context menu, and you can use %1 to refer to the currently selected file i.e. for MS Access I use :

HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"

This then adds a context menu item for any file I select (hence the *), which allows me to launch it in MS Access 2000.

Of course, always back up your registry before hacking it.

Your program could do this during install, or on first run.

最美的太阳 2024-07-16 15:51:28

您还可以将 java 程序打包在 NSIS 等安装程序中,并且可以使用 NSIS 脚本生成资源管理器上下文菜单

You could also package the java program in an installer like NSIS and you could use NSIS script to generate explorer context menu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文