从 Firefox 中将任意文件作为 windows bat 文件运行?

发布于 2024-11-10 07:41:42 字数 1027 浏览 4 评论 0原文

假设我有一个文件扩展名为 .batscript 的 Windows 批处理文件,并设置了一个 Web 服务器来为其提供内容类型 application/x-批脚本。如何将 Firefox 4 设置为“始终打开”该文件,以便它作为标准批处理文件运行? (我可以访问电脑,但希望避免创建/安装外部程序/扩展/插件)

我不能直接使用 .bat 因为 Firefox 不允许直接打开它们;它们必须单独保存和运行(出于明显的安全原因)。

运行批处理文件的标准方法是 cmd /c %1,其中 %1 是 bat 文件的路径,但这在 % 时不起作用1 是具有自定义文件扩展名(例如 .batscript)的文件的路径,因为 cmd 查找应用程序 %1 > 应该打开,因此通过注册表添加直接文件关联不起作用(它会递归地打开cmd提示符)。

相反,我找到了一种解决方法,可以将 .batscript 文件临时复制到 .bat 文件并使用注册表项 像这样,它允许我双击 .batscript 文件来运行它。但 Firefox 不尊重这些平台文件关联!

好的,Firefox 希望我为每种内容类型单独定义文件类型关联:很公平,文件扩展名和文件类型关联。内容类型并不总是相同的。但我只能让 Firefox 运行离散的应用程序,并且批处理脚本需要使用 cmd.exe /c %1 运行,而不仅仅是 cmd %1

有谁知道强制 Firefox 使用系统文件关联或允许使用命令行参数启动任意程序的方法吗?

(对于那些想知道的人来说,用例类似于“一个内部网络应用程序,它允许用户通过单击链接来运行具有不同数量的命令行参数的本地程序”——这些小“突破沙箱”的替代解决方案“有问题也欢迎!)

Say I've got a windows batch file with a file extension .batscript, and say I've got a web server set up to serve it with a content-type of application/x-batscript. How can I set up Firefox 4 to "always open" this file so that it runs as a standard batch file would? (I have access to the PCs but want avoid creating/installing external programs/extensions/plugins)

I can't use a straight .bat because Firefox doesn't allow those to be opened directly; they have to be saved and run separately (for obvious security reasons).

The standard way to run a batch file is cmd /c %1 where %1 is the path to the bat file, but this doesn't work when %1 is a path to a file with a custom file extension (such as .batscript) because cmd looks up what application %1 should be opened with, so adding a direct file association via the registry doesn't work (it recursively opens cmd prompts).

Instead, I found a work around where I temporarily copy my .batscript file to a .bat file and run it, using registry entries like this, which allows me to double click on a .batscript file to run it. But Firefox doesn't respect these platform file associations!

Ok, so Firefox wants me to define my file type associations separately for each content-type: fair enough, file extensions & content-types aren't always the same. But I can only get Firefox to run discrete applications, and a batch script needs to be run with cmd.exe /c %1 not just cmd %1.

Does anybody know of a way to force Firefox to either use the system file association or allow launching arbitrary programs with command line parameters?

(For those wondering, the use case is similar to "an internal web app which allows users to run a local program with a varying amount of command line parameters by clicking on a link" - alternative solutions to these small "breaking out of the sandbox" problems are also welcome!)

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

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

发布评论

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

评论(1

冷…雨湿花 2024-11-17 07:41:42

我认为您需要编辑 MimeTypes.rdf 文件。如需了解更多信息,另请参阅此页面

I think you need to edit the MimeTypes.rdf file. For more information see also this page.

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