简体   繁体   English

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

[英]How do I get the path to the associated file used to launch a program?

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. 最初我以为文件路径在Environment.CommandLine中,但是命令行仅包含程序路径。

I specified the file association using the Publish Options in visual studio like so: extension: .ext, Description: Some File, ProgId: ProjectName, Icon: SomeIcon.ico. 我使用Visual Studio中的“发布选项”指定了文件关联,如下所示:扩展名:.ext,说明:某些文件,ProgId:ProjectName,图标:SomeIcon.ico。

You are right, it should indeed be passed as a command line argument and be available through Environment.CommandLine . 没错,它确实应该作为命令行参数传递,并且可以通过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. 是一篇过时但仍然有用的TechNet文章,介绍了这些方法的工作原理。 In particular, the "%1" in the screenshot below is essential. 特别是,下面的屏幕快照中的"%1"是必不可少的。

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

I'm not sure about the DDE thing, so if you're not using it, turn it off. 我不确定DDE,因此,如果您不使用它,请将其关闭。

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. 如果您在注册表中的“打开”命令中查找文件类型,则该命令可能配置为“ c:\\ your-company \\ your-app.exe”,而不是“ c:\\ your-company \\ your” -app.exe“”%1“,这是您希望文件路径显示在命令行上时所需要的。

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

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