Question

I have DLL With BHO IE Plugin.

And I use "regasm.exe /codebase myBHO.dll" to register my dll.

Is there any C# code to regasm my DLL in windows application?

Was it helpful?

Solution

Create a dedicated installer for this.

For quick debugging cycles from Visual Studio, setup some Build Events like so:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\gacutil.exe" /f /i $(TargetDir)$(TargetFileName) 
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /unregister $(TargetDir)$(TargetFileName)
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" $(TargetDir)$(TargetFileName) /regfile:$(TargetFileName)64.reg
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /codebase $(TargetDir)$(TargetFileName)

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /f /i $(TargetDir)$(TargetFileName) 
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" /unregister $(TargetDir)$(TargetFileName)
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" $(TargetDir)$(TargetFileName) /regfile:$(TargetFileName)32.reg
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" /codebase $(TargetDir)$(TargetFileName)

Then, define a [ComRegisterFunction] like:

[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
    RegistryKey key;
    using (key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects"))
    {
      RegistryKey bhoKey;
      using (bhoKey = key.CreateSubKey(typeName))
      {
        bhoKey.SetValue(string.Empty, "My Awesone IE Plugin");
        bhoKey.SetValue("NoExplorer", 1, RegistryValueKind.DWord);
      }
    }      
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top