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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1838856/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 21:18:23  来源:igfitidea点击:

Integrating into Windows Explorer context menu

c#.netexplorerfile-extension

提问by clamp

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. If it's not possible I could also do it with C++/Win32.

我想为此使用 C#/.NET 2.0。如果不可能,我也可以用 C++/Win32 来完成。

My questions are:

我的问题是:

  1. Is it possible with C# .NET 2.0?
  2. What are the necessary functions for integrating into the Windows Explorer context menu?
  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.)
  1. C# .NET 2.0 有可能吗?
  2. 集成到 Windows 资源管理器上下文菜单中的必要功能是什么?
  3. 我怎样才能使它永久化?(我不想在每次启动后重新启动这个工具)
  4. 我需要特别注意什么?(不同的操作系统、安全权限等)

采纳答案by Mark Bell

You will need to access the registry and add a key under root\\File\\shellor root\Folder\\shell, depending on which items you want the menu item visible on.

您将需要访问注册表并在root\\File\\shell或下添加一个键root\Folder\\shell,具体取决于您希望菜单项可见的项目。

Try this article at CodeProject, it's quite useful.

在 CodeProject试试这篇文章,它非常有用。

Edit: There's another article herewhich may be of help.

编辑:这里还有另一篇文章可能会有所帮助。

回答by DrPizza

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; one for .NET 3.5, one for .NET 1. Which runtime will get loaded into your process? Well, it's more or less random--it depends which shell extension gets loaded first. Sometimes it might be the 2.0 runtime, sometimes it might be the 1.1 runtime.

考虑一下您有两个 shell 扩展的情况;一种用于 .NET 3.5,一种用于 .NET 1. 哪个运行时将加载到您的进程中?好吧,它或多或少是随机的——这取决于首先加载哪个 shell 扩展。有时可能是 2.0 运行时,有时可能是 1.1 运行时。

This is also an issue if a .NET program creates common file dialogs; your shell extension may or may not load, and may or may not run with the correct runtime version.

如果 .NET 程序创建公共文件对话框,这也是一个问题;您的 shell 扩展可能会或可能不会加载,并且可能会或可能不会以正确的运行时版本运行。

As such, if you go down the Shell extension routeyou should use native C++/COM/Win32.

因此,如果您沿着Shell 扩展路线走下去,您应该使用本机 C++/COM/Win32。