Change Windows Service properties Through CustomAction

Jul 2, 2015 at 2:36 PM
Edited Jul 2, 2015 at 2:39 PM

I've managed to pass properties from External UI to the MSI using Custom Actions.
(I checked it with MessageBox):

session.CustomActionData["ServiceName"] = session.CustomActionData["NAMEKEY"];

The way I create my property is:
p = new Property("ServiceName", "TestTest");

I also add the property name to UsesProperties
m.UsesProperties = "ServiceName";

and then I add it to the project:
project.Properties = new Property[]

The way I set the name for the service is:
Name = "[ServiceName]"

When I tried to set property directly from session I get errors:
session["ServiceName"] = session.CustomActionData["NAMEKEY"];
When I do deffered its says I am not allowed access properties
When I do immediate it says There is no such a key.

So the issue is, my service name keeps default value instead of a new value that I set inside CustomAction.

Any suggestions would be much appreciated!

Thank you,
Eduards Brown
Jul 2, 2015 at 3:25 PM

I've fixed it:

In SetPropertyAction set the name to Service name! and inside Value instead of doing Key/Value pair, just do value!
Marked as answer by edik009 on 7/2/2015 at 8:25 AM
Jul 3, 2015 at 2:42 AM
Edited Jul 3, 2015 at 2:49 AM

Though there are a few things that look strange in your code fragments. Specifically you are reading your property value from CustomActionData, meaning you are in the the deferred action (e.g. after setup is completed). Often (but not always) the session object is 'disconnected' if it is accessed from the deferred action. Thus property cannot be set back to the session.

However it's only a part of the problem. Your 'ServiceName' property is not all in capital, maeaning it cannot be set from the outside (e.g. ExternalUI). Yes MSI is using this childish technique to make property 'public'. The all characters supposed to be capital.

The typical scenario for setting properties from ExternalUI is to collect user input prior the actual installation and then pass it to the MSI runtime. ExternalUI/WpfSetup sample does exactly that when user chooses (checkbox) if the "Documentation" feature should be installed.

If you do it this way your code can be as simple as:
public void StartInstall()
   base.StartInstall("SERVICENAME=" + svcNameCtrl.Text);
Marked as answer by edik009 on 7/3/2015 at 1:05 AM