First of all i am new to windows programming, sorry for using any wrong terminologies. I have created a c# BHO and i am able to register dll through Visual Studio Command Prompt(Run as Administrator) using below command on windows 7 64-bit.
regasm.exe HelloBHOWorld1.dll /codebase
as mention in this question How to unregister the assembly registered using regasm
This my RegisterBHO and UnregisterBHO method.
public static string BHOKEYNAME =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (registryKey == null)
registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
string guid = type.GUID.ToString("B");
RegistryKey ourKey = registryKey.OpenSubKey(guid);
if (ourKey == null)
ourKey = registryKey.CreateSubKey(guid);
ourKey.SetValue("Alright", 1);
registryKey.Close();
ourKey.Close();
}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guid = type.GUID.ToString("B");
if (registryKey != null)
registryKey.DeleteSubKey(guid, false);
}
I am creating exe using NSIS to register BHO during installation. I tried below commands one by one in NSIS to register it.
ExecWait '"$SYSDIR\regsvr32.exe" /s "$INSTDIR\ie\HelloBHOWorld.dll"'
ExecWait 'regasm.exe "$INSTDIR\ie\HelloBHOWorld.dll" /register /codebase /tlb'
RegDLL "$INSTDIR\ie\HelloBHOWorld1.dll"
ExecWait '"$SYSDIR\rundll32.exe" $INSTDIR\ie\HelloBHOWorld.dll DllRegisterServer'
Nothing is working for me. What am i doing wrong? What is correct way?