使用 .NET 的 Windows Shell 集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/437972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Shell Integration using .NET
提问by prestomation
What's the easiest/best way to register your program in explorers right-click menu using .NET and C#?
i.e. I would like to be able to right-click on an item in windows explorer and get a "Edit with MyProgram"
使用 .NET 和 C# 在资源管理器右键单击菜单中注册程序的最简单/最佳方法是什么?
即我希望能够在 Windows 资源管理器中右键单击一个项目并获得“使用 MyProgram 编辑”
This is the closest thing to a tutorial I could findbut it mostly just dips into Win32 from .NET and is also outdated. How should this be done now?
这是我能找到的最接近教程的东西,但它主要是从 .NET 进入 Win32 并且已经过时了。现在应该怎么做?
回答by JD Conley
If you just want to add menu items, then a shell extension is overkill. You can register a command line in the registry which will run your exe with the selected file(s) as the parameter. Shell extensions are really only required if you want to change explorer's behavior, add custom icons, or hook shell based file operations.
如果您只想添加菜单项,那么 shell 扩展就有点过分了。您可以在注册表中注册一个命令行,该命令行将使用所选文件作为参数运行您的 exe。只有当您想更改资源管理器的行为、添加自定义图标或挂钩基于 shell 的文件操作时,才真正需要外壳扩展。
http://www.codeproject.com/KB/shell/SimpleContextMenu.aspx
http://www.codeproject.com/KB/shell/SimpleContextMenu.aspx
If a shell extension is what you need, you're best writing a thin wrapper in unmanaged code that calls out to another process that is your .NET application through some sort of cross process communication channel. Due to all the potential versioning issues, it's not recommended to load the .NET runtime into the explorer process.
如果您需要外壳扩展,则最好在非托管代码中编写一个瘦包装器,通过某种跨进程通信通道调用另一个进程,即您的 .NET 应用程序。由于所有潜在的版本控制问题,不建议将 .NET 运行时加载到资源管理器进程中。