Regasm BHO from C# Code

橙三吉。 提交于 2019-12-23 05:36:10

问题


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?


回答1:


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);
      }
    }      
}


来源:https://stackoverflow.com/questions/16579488/regasm-bho-from-c-sharp-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!