简体   繁体   中英

Register Com c# BHO DLL using NSIS

First of all i am new to windows programming, sorry for using any wrong terminologies. I have created ac# 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?

The ExecWait NSIS instruction just uses the CreateProcess() and WaitForSingleObject() WinAPI functions so you can probably run regasm.exe manually first to make sure that is actually working.

You can try to see where it goes wrong (cannot load dll? cannot write to the registry?) with Process Monitor ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM