[英]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.