I need to modify a config. file by running a custom action after "InstallServices" step.
The problem is that after the InstallServices step, and even after MsiConfigureServices step, the Files and Folders are not yet installed (copied) on the user's machine.
The goal: run a custom action to modify a config file before the "StartService" step kicks in.
Problem:
Why are the files not installed before the service is started - shouldn't the files be copied by the time the service is to be started? Where is it starting it from then - since there are no files?
The files are, indeed, installed on the machine before the "InstallServices" step, otherwise the services could not be started. However, the "InstallFile" action is executed as "Deferred" not as "Immediately". Can you set the "When the system is being modified (deferred)" and "Run under the LocalSystem account (no impersonation)" options for your custom action and see if it works?
"The files are, indeed, installed on the machine before the "InstallServices" step, otherwise the services could not be started. "
The above statement is NOT what I am seeing in my machine. The service is started but there are NO FILES in the C:\Program Files\...[etc].
That was my question, why is the service started when there are no files in the system....
Anyways, I found a work-around:
I though I should share with anyone having this same issue:
1. Do NOT set your service to "Start Once Installed"
2. In your custom action must go AFTER "InstallFinalize" -> TO GUARANTEE THE FILES ARE COPIED TO THE PC. (It seems the files are finally copied AFTER "StartServices"; I do not know why but it's true)
3. In you custom action, start the service yourself:
private static void StartService()
{
try
{
//session.Log("Starting Your Service.");
ServiceController service = new ServiceController("YourService.exe");
if (service.Status != ServiceControllerStatus.Running)
{
service.Start();
var timeout = new TimeSpan(0, 0, 5);
}
}
catch (Exception ex)
{
// Swallowing this exception on purpose. If the Service doesn't start (which shouldn't happen), the user can start it manually.
}
}
I'm glad you got this working and thank you for sharing your solution with us.
However, please keep in mind that there is no way for the services to start without the files to be copied on the machine. The Windows Installer normal behavior is for the files to be copied first and the services to be started later. If you are on a 64-bit machine, you can check the "C:\Program Files (x86)\...[etc]" path.
FOLLOW US
Get the latest news in Application Packaging