繁体   English   中英

使用NSIS注册Com c#BHO DLL

[英]Register Com c# BHO DLL using NSIS

首先,我是Windows编程的新手,很抱歉使用任何错误的术语。 我已经创建了ac#BHO,并且能够在Windows 7 64位上使用以下命令通过Visual Studio命令提示符(以管理员身份运行)注册dll。

regasm.exe HelloBHOWorld1.dll /codebase

如本问题所述如何取消注册使用regasm注册的程序集

这是我的RegisterBHO和UnregisterBHO方法。

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

我正在使用NSIS创建exe来在安装过程中注册BHO。 我在NSIS中逐个尝试以下命令进行注册。

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'

什么都没有为我工作。 我究竟做错了什么? 什么是正确的方法?

ExecWait NSIS指令仅使用CreateProcess()WaitForSingleObject() WinAPI函数,因此您可能可以首先手动运行regasm.exe以确保其实际运行。

您可以尝试使用Process Monitor查看错误信息(无法加载dll?无法写入注册表?)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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