如何获取用于启动程序的关联文件的路径?

发布于 2024-08-26 08:59:23 字数 204 浏览 4 评论 0原文

我有一个具有关联文件类型的程序。但是,当我双击文件启动程序时,我无法弄清楚该路径传递给程序的位置。

最初我以为文件路径会在Environment.CommandLine中,但命令行只包含程序路径。

我使用 Visual Studio 中的发布选项指定了文件关联,如下所示:扩展名:.ext,描述:某些文件,ProgId:项目名称,图标:SomeIcon.ico。

I have a program with an associated file type. However, when I double-click a file to launch the program, I can't figure out where that path was passed to the program.

Initially I thought the file path would be in Environment.CommandLine, but the command line only contained the program path.

I specified the file association using the Publish Options in visual studio like so: extension: .ext, Description: Some File, ProgId: ProjectName, Icon: SomeIcon.ico.

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

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

发布评论

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

评论(2

自在安然 2024-09-02 08:59:23

你是对的,它确实应该作为命令行参数传递,并可以通过Environment.CommandLine使用。

我的猜测是文件关联本身有问题。 这里是一篇关于这些东西如何工作的过时但仍然有用的 TechNet 文章。特别是下面截图中的“%1”是必不可少的。

操作编辑对话框的屏幕截图

我是不确定 DDE 的情况,所以如果您不使用它,请将其关闭。

You are right, it should indeed be passed as a command line argument and be available through Environment.CommandLine.

My guess is that something is wrong with the file association itself. Here is a dated but still useful TechNet article on how these things work. In particular, the "%1" in the screenshot below is essential.

Screenshot of action editing dialog

I'm not sure about the DDE thing, so if you're not using it, turn it off.

温柔戏命师 2024-09-02 08:59:23

据猜测,您的文件类型关联可能配置不正确。如果您在注册表中查找文件类型的“打开”命令,该命令可能配置为“c:\your-company\your-app.exe”,而不是“c:\your-company\your-app.exe” -app.exe" "%1",如果您希望文件路径显示在命令行上,则需要使用该名称。

As a guess, your file type association may not be configured properly. If you look in the registry at your "Open" command for your file type, the command is probably configured as "c:\your-company\your-app.exe", instead of as "c:\your-company\your-app.exe" "%1", which is what it would need to be if you wanted the file path to show up on the command line.

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