Archive: Register a BHO through an NSIS installer


Register a BHO through an NSIS installer
I have an IE BHO which I was packaging through the Visual Studio setup and deployment project. I now want to the package it through an NSIS installer.

My BHO was registering in the following way:

[ComRegisterFunctionAttribute]
public static void Register(Type t)
{
string guid = t.GUID.ToString("B");

RegistryKey rkClass = Registry.ClassesRoot.CreateSubKey(@"CLSID\"+guid );
RegistryKey rkCat = rkClass.CreateSubKey("Implemented Categories");

string name = toolbarName;
string help = toolbarHelpText;

rkClass.SetValue(null, name );
rkClass.SetValue("MenuText", name );
rkClass.SetValue("HelpText", help );

if( 0 != (style & BandObjectStyle.Vertical) )
rkCat.CreateSubKey("{00021493-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.Horizontal) )
rkCat.CreateSubKey("{00021494-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.TaskbarToolBar) )
rkCat.CreateSubKey("{00021492-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.ExplorerToolbar) )
Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Toolbar").SetValue(guid,name);

}

While this is taken care of by the msi installer that is made by VS, I want to know how can I do the same using NSIS?

Any help would be appreciated!

Kapil


If it's just a matter of writing those registry values then you've got all the registry functions in the NSIS documentation. You'll just have to get the GUID and pass it to NSIS. You could do this via a .NET DLL (invoked using the CLR plug-in) or via a .NET console app which you execute with ExecDos/nsExec.

Stu


Originally posted by kumar.kapil
RegistryKey rkClass = Registry.ClassesRoot.CreateSubKey(@"CLSID\"+guid );
RegistryKey rkCat = rkClass.CreateSubKey("Implemented Categories");

string name = toolbarName;
string help = toolbarHelpText;

rkClass.SetValue(null, name );
rkClass.SetValue("MenuText", name );
rkClass.SetValue("HelpText", help );

if( 0 != (style & BandObjectStyle.Vertical) )
rkCat.CreateSubKey("{00021493-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.Horizontal) )
rkCat.CreateSubKey("{00021494-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.TaskbarToolBar) )
rkCat.CreateSubKey("{00021492-0000-0000-C000-000000000046}");

if( 0 != (style & BandObjectStyle.ExplorerToolbar) )
Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Toolbar").SetValue(guid,name);
Your GUID should be known, than you can do it all by yourself using the Registry functions WriteRegXXX of NSIS.

If your shell extension DLL (hopefully) meets the Microsoft design guidlines there is also an much more easier way:

You can use the exported function DllRegisterServer (and for uninstalling DllUnregisterServer). This can easyly done using "RegSvr32.exe". This would be in NSIS like this command:

Install:
ExecWait "$SYSDIR\regsvr32.exe /s $\"$INSTDIR\YourDLLName.dll$\""

Uninstall:
ExecWait "$SYSDIR\regsvr32.exe /s /u $\"$INSTDIR\YourDLLName.dll$\""


It is important tu use quotation marks in the command argument of RegSvr32 since the setup directory may contain spaces. If the quotation marks are missing the command argument will be cut at the first space in the argument by RegSvr32!

In case your shell extension DLL does not support the registering and unregistering process completely I advice you to implement this in you DLL. This may be needed in case a re-registering or a manual unregistering is nesessary. This makes life much much easier for your customer support!

hope this helped a little!?

Best regards

th_mi

Do you have to use regsvr32? What about NSIS's RegDLL?

Stu


Originally posted by Afrow UK
Do you have to use regsvr32?
No, if you know RegDLL :)

Originally posted by Afrow UK
What about NSIS's RegDLL?
Now I can use it, since I know it ;)