Shell integrates into Windows for a specific file type using C #

So, I was looking for guidance on how the shell integrates your application (add it to the context menu) using C #, but I could not find how to do this only for a specific file type. I know this is possible because WinRar does this. So how can I do this?

+4
source share
2 answers

Typically, you can implement this in two ways.

  • Registry keys - you can write keys and values โ€‹โ€‹under HKEY_CLASSES_ROOT. If you look at this hive, you will see extensions on your computer. Look at the article for more information on keys and values. Something simple is possible here, for example, the ability to open .myfile types with your application. Here is an example file association

  • Shell Extensions (written in COM): here you can do more complex things like Handlers. They will be caused by Windows, so you can do things like paint on the menu, or add custom actions when you right-click. There are more than files here, you can even add property sheets and custom hints.

You will find that you do not use .NET to write a shell handler **. This only applies to older versions of .NET. Everything is fine with .NET4.

This article should help you with the context menu handler in .NET4.

** Why was he not recommend:

When you write a shell handler, it is invoked by the host process (usually Windows Explorer), but also by the Dialogs FileOpenDialogs and FolderBrowser. So the problem will arise if you wrote a shell extension in .NET 2.0 and a .NET 1.1 application called the Open File dialog box, and then a .NET 2.0 shell handler, and your .NET 1.1 application that has an earlier version of the CLR and There will be a version conflict.

So, I'm glad I found out that this was somehow fixed in .NET 4 =)

+7
source

Right-click management in Windows Explorer is controlled by the registry. In particular, the hive HKEY_CLASSES_ROOT.

A good way to get an idea of โ€‹โ€‹how everything works there is to check out HKCR\.txt , which shows what happens with the text files in the right-click menu. Look at the key (by default) that points to "txtfile". HKCR\txtfile will have a subkey HKCR\txtfile\shell\open\comman d. The (default) key for this command shows the command to open notepad.exe with the parameter "% 1", which indicates the opening of the file. Replace the public key with a different name (see Print and print keys in the txtfile key) to add another user command to the context menu.

Once you understand what you need to add to integrate your application, you can check the Microsoft.Win32 namespace for classes to help manipulate the registry using C # code.

+1
source

Source: https://habr.com/ru/post/1345436/


All Articles