This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Properties in a custom action (.net assembly)
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 02, 2009
03:07 PM
Properties in a custom action (.net assembly)
Hi there,
I've got a custom action calling into a .NET C# assembly to do some installation work for me.
I've got a class in my namespace like this:
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public void Test()
{
MessageBox.Show("I MADE IT!");
}
}
And I can get the custom action to call my Test() routine no problem. However, I want to get at the properties in the installation, like INSTALLDIR and such, but can't seem to. I've seen other code do things like this:
string sArg = this.Context.Parameters["INSTALLDIR"];
But it doesn't seem like that's defined in my Test() function; because I get exceptions when I try to use that Context object.
Any help would be appreciated.
Chris
I've got a custom action calling into a .NET C# assembly to do some installation work for me.
I've got a class in my namespace like this:
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public void Test()
{
MessageBox.Show("I MADE IT!");
}
}
And I can get the custom action to call my Test() routine no problem. However, I want to get at the properties in the installation, like INSTALLDIR and such, but can't seem to. I've seen other code do things like this:
string sArg = this.Context.Parameters["INSTALLDIR"];
But it doesn't seem like that's defined in my Test() function; because I get exceptions when I try to use that Context object.
Any help would be appreciated.
Chris
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 02, 2009
03:37 PM
the only way I know of to access the installer properties in C# code is to put a reference to Installshield.interop.msi.dll in your project and place a using statement #using Installshield.Interop;
Your function signature will need to look like
public void Test(Int32 handle)
{
Msi.Installer installer = Msi.CustomActionHandle(handle);
// then you can do the getproperty to get the public properties
string installDir = installer.GetProperty("INSTALLDIR");
}
when you call the custom action in your Installer you will need to pass it the MsiHandle, it is in the drop down list of options to pass when you use the custom signature for the method call.
If you are using your custom action DLL stored in the binary table you will need to add a line to the ISClrWrap table for each custom action that uses your DLL.
Action | Type | Value
|Dependency0 | system\Installshield.Interop.msi.dll
Your function signature will need to look like
public void Test(Int32 handle)
{
Msi.Installer installer = Msi.CustomActionHandle(handle);
// then you can do the getproperty to get the public properties
string installDir = installer.GetProperty("INSTALLDIR");
}
when you call the custom action in your Installer you will need to pass it the MsiHandle, it is in the drop down list of options to pass when you use the custom signature for the method call.
If you are using your custom action DLL stored in the binary table you will need to add a line to the ISClrWrap table for each custom action that uses your DLL.
Action | Type | Value
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 15, 2009
04:12 PM
Hi there,
So, I've done as you suggested above. I made the custom action, added the reference so my project builds, and then I have 2 custom actions.
The first one calls the Test() routine below, with no issues.
Right after that one, I have another custom action that calls InstallCertificate(), passing the MsiHandle as you describe. I never get into that routine - no popup, nothing - just a "fatal error" from the installer, and the installation stops.
(As a side note, I notice that my pfx file isn't on the PC yet in the INSTALLDIR, so I have to move that CA lower in the process, I'm sure).
Any tips?
using InstallShield.Interop;
namespace Nuance.NAS.Server
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public void Test()
{
MessageBox.Show("I MADE IT!");
}
public void InstallCertificate(Int32 handle)
{
MessageBox.Show("I'm here!");
Msi.Install installer = Msi.CustomActionHandle(handle);
string sWhere = installer.GetProperty("INSTALLDIR");
string sMsg = string.Format("Installing certificate...{0}", sWhere);
MessageBox.Show(sMsg);
try
{
MessageBox.Show("Creating X509 store...");
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
MessageBox.Show("Opening X509 store...");
store.Open(OpenFlags.ReadWrite);
string sPath = Path.Combine(sWhere, "foo.pfx");
X509Certificate2 cert = new X509Certificate2(sPath, "password");
MessageBox.Show("Adding CERT...");
store.Add(cert);
}
catch (Exception e)
{
sMsg = string.Format("Exception {0} installing certificate.", e.Message);
MessageBox.Show(sMsg);
}
MessageBox.Show("Server certificate installed.");
}
}
So, I've done as you suggested above. I made the custom action, added the reference so my project builds, and then I have 2 custom actions.
The first one calls the Test() routine below, with no issues.
Right after that one, I have another custom action that calls InstallCertificate(), passing the MsiHandle as you describe. I never get into that routine - no popup, nothing - just a "fatal error" from the installer, and the installation stops.
(As a side note, I notice that my pfx file isn't on the PC yet in the INSTALLDIR, so I have to move that CA lower in the process, I'm sure).
Any tips?
using InstallShield.Interop;
namespace Nuance.NAS.Server
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public void Test()
{
MessageBox.Show("I MADE IT!");
}
public void InstallCertificate(Int32 handle)
{
MessageBox.Show("I'm here!");
Msi.Install installer = Msi.CustomActionHandle(handle);
string sWhere = installer.GetProperty("INSTALLDIR");
string sMsg = string.Format("Installing certificate...{0}", sWhere);
MessageBox.Show(sMsg);
try
{
MessageBox.Show("Creating X509 store...");
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
MessageBox.Show("Opening X509 store...");
store.Open(OpenFlags.ReadWrite);
string sPath = Path.Combine(sWhere, "foo.pfx");
X509Certificate2 cert = new X509Certificate2(sPath, "password");
MessageBox.Show("Adding CERT...");
store.Add(cert);
}
catch (Exception e)
{
sMsg = string.Format("Exception {0} installing certificate.", e.Message);
MessageBox.Show(sMsg);
}
MessageBox.Show("Server certificate installed.");
}
}