简体   繁体   English

集成到 Windows 资源管理器上下文菜单中

[英]Integrating into Windows Explorer context menu

I want to write a small tool, that does the following:我想写一个小工具,它执行以下操作:

When you right click on a file with a certain file-extension the Windows Explorer context menu shows an additional entry.当您右键单击具有特定文件扩展名的文件时,Windows 资源管理器上下文菜单会显示一个附加条目。

When you click this entry a certain EXE is launched with this file as one of its parameters.当您单击此条目时,将使用此文件作为其参数之一启动某个 EXE。

I would like to use C#/.NET 2.0 for this.我想为此使用 C#/.NET 2.0。 If it's not possible I could also do it with C++/Win32.如果不可能,我也可以用 C++/Win32 来完成。

My questions are:我的问题是:

  1. Is it possible with C# .NET 2.0? C# .NET 2.0 有可能吗?
  2. What are the necessary functions for integrating into the Windows Explorer context menu?集成到 Windows 资源管理器上下文菜单中的必要功能是什么?
  3. How can I make this permanent?我怎样才能使它永久化? (I don't want to relaunch this tool after every boot) (我不想在每次启动后重新启动这个工具)
  4. What do I have to take special care of?我需要特别注意什么? (different OS, security permissions, etc.) (不同的操作系统、安全权限等)

You will need to access the registry and add a key under root\\\\File\\\\shell or root\\Folder\\\\shell , depending on which items you want the menu item visible on.您将需要访问注册表并在root\\\\File\\\\shellroot\\Folder\\\\shell下添加一个键,具体取决于您希望菜单项可见的项目。

Try this article at CodeProject , it's quite useful.在 CodeProject试试这篇文章,它非常有用。

Edit: There's another article here which may be of help.编辑:这里还有另一篇文章可能会有所帮助。

It is, incidentally, not supported to use .NET for shell extensions, due to the current inability to host multiple runtime versions in the same process (.NET 4 will lift this restriction).顺便说一句,不支持将 .NET 用于外壳扩展,因为当前无法在同一进程中承载多个运行时版本(.NET 4 将取消此限制)。

Consider the case where you have two shell extensions;考虑一下您有两个 shell 扩展的情况; one for .NET 3.5, one for .NET 1. Which runtime will get loaded into your process?一种用于 .NET 3.5,一种用于 .NET 1. 哪个运行时将加载到您的进程中? Well, it's more or less random--it depends which shell extension gets loaded first.好吧,它或多或少是随机的——这取决于首先加载哪个 shell 扩展。 Sometimes it might be the 2.0 runtime, sometimes it might be the 1.1 runtime.有时可能是 2.0 运行时,有时可能是 1.1 运行时。

This is also an issue if a .NET program creates common file dialogs;如果 .NET 程序创建通用文件对话框,这也是一个问题; your shell extension may or may not load, and may or may not run with the correct runtime version.您的 shell 扩展可能会或可能不会加载,并且可能会或可能不会以正确的运行时版本运行。

As such, if you go down the Shell extension route you should use native C++/COM/Win32.因此,如果您沿着Shell 扩展路线走下去,您应该使用本机 C++/COM/Win32。

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

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