How to register a namespace extension written in C # in the vista registry

Good morning,

After a day of trekking, Im at a loss. I decided to come here and ask about it. I am doing a namespace extension for vista in C #. Now I understand that MS says not to do this, but I just do it as a proof of concept.

Problem: I lack knowledge and understanding to figure out how to register a .NET namespace extension in the Windows registry.

From my reading, I believe that this post ([] How to place an extension with a name extension in Windows Explorer ) explains where the key belongs, but do I need to create sub-keys and / or values โ€‹โ€‹inside?

I understand that regsvr32 and / or regasm.exe must be used to register my dll (not sure if I found conflicting tips).

I also understand that my dll should have a method similar to the following:

(This code mainly comes from [] http://msdn.microsoft.com/en-us/magazine/cc188741.aspx , minor changes to add to the correct place to register)

[ComRegisterFunctionAttribute] public static void RegisterFunction(Type t) { try { // add the correct things to the CLSID so the thing works as an extension RegistryKey CLSID = Registry.ClassesRoot.OpenSubKey("CLSID"); RegistryKey kClass = null; kClass = CLSID.OpenSubKey( "{" + t.GUID.ToString() + "}", true ); RegistryKey ProgId = kClass.OpenSubKey("ProgId"); kClass.SetValue( null, (string) ProgId.GetValue(null) ); ProgId.Close(); RegistryKey ShellFolder = kClass.CreateSubKey("ShellFolder"); ShellFolder.SetValue( "Attributes", 0x78000040 ); ShellFolder.SetValue( "WantsFORPARSING", "" ); ShellFolder.Close(); kClass.Close(); CLSID.Close(); // add it to the approved list of extensions RegistryKey MyComputer = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\NameSpace", true); MyComputer.SetValue("{" + t.GUID.ToString() + "}", t.FullName); MyComputer.Close(); } catch( Exception e ) { MessageBox.Show( e.Message ); return; } } 

Resources for people in this future situation who will find this by searching: [] http://msdn.microsoft.com/en-us/magazine/cc188741.aspx

[] http://msdn.microsoft.com/en-us/library/bb762774(VS.85).aspx

[] How to place a proxy namespace extension in Windows Explorer

--- Update from 3/10/10 ---

I tried to do some work with him, but still did not succeed. So I pulled out everything I had to investigate how regasm works with the registry.

My code is:

 using System; using Microsoft.Win32; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Test2 { [ProgId("Test2")] [Guid("1149E580-186E-4f8c-AB6A-E55D6F0F171E")] [ComVisible(true)] public class Class1 { [ComRegisterFunctionAttribute()] public static void RegisterFunction(Type t) { // add the correct things to the CLSID so the thing works as an extension System.IO.FileStream fs = new System.IO.FileStream(@"C:\Users\Lucas\Documents\Visual Studio 2010\Projects\Test2\Test2\bin\Release\Test2.txt", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None); fs.Write(System.Text.Encoding.ASCII.GetBytes("Running RegisterFunction"), 0, 0); fs.Close(); RegistryKey CLSID = Registry.ClassesRoot.OpenSubKey("CLSID"); RegistryKey kClass = CLSID.CreateSubKey("{" + t.GUID.ToString() + "}"); kClass.SetValue("Test", "HelloRegistry", RegistryValueKind.String); kClass.Close(); CLSID.Close(); } [ComUnregisterFunctionAttribute()] public static void UnregisterFunction(Type t) { } } } 

I create a dll, then run regasm / regfile [: pathtofile] [pathtodll] and the registry file will be created as follows:

 REGEDIT4 [HKEY_CLASSES_ROOT\Test2] @="Test2.Class1" [HKEY_CLASSES_ROOT\Test2\CLSID] @="{1149E580-186E-4F8C-AB6A-E55D6F0F171E}" [HKEY_CLASSES_ROOT\CLSID\{1149E580-186E-4F8C-AB6A-E55D6F0F171E}] @="Test2.Class1" [HKEY_CLASSES_ROOT\CLSID\{1149E580-186E-4F8C-AB6A-E55D6F0F171E}\InprocServer32] @="mscoree.dll" "ThreadingModel"="Both" "Class"="Test2.Class1" "Assembly"="Test2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" "RuntimeVersion"="v4.0.21006" [HKEY_CLASSES_ROOT\CLSID\{1149E580-186E-4F8C-AB6A-E55D6F0F171E}\InprocServer32\1.0.0.0] "Class"="Test2.Class1" "Assembly"="Test2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" "RuntimeVersion"="v4.0.21006" [HKEY_CLASSES_ROOT\CLSID\{1149E580-186E-4F8C-AB6A-E55D6F0F171E}\ProgId] @="Test2" [HKEY_CLASSES_ROOT\CLSID\{1149E580-186E-4F8C-AB6A-E55D6F0F171E}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}] 

Note that nothing from my custom key and txt document is ever created. Therefore, it makes me think that regasm never calls my registration method. If anyone has any ideas, I will be more than happy to try them!

+4
source share
1 answer
  • You need to run regasm.exe, not regsvr32.exe
  • You need to make sure that you are registered while working as an administrator.
  • Finally, you also need to create the following registry key HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\Namespace\{CLSID of your root class} and set the default value for the display name of your namespace extension. It is assumed that you register in the "My Computer" section.
  • Add it to the approved extensions in the following registry subkey: HKLM\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved . To this key, create a new value with a name equal to the CLSID of your namespace extension and a value equal to the display name of your namespace extension.
+2
source

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


All Articles