cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sureshkottakki
Level 6

Allow not to start the service

Hi,
I have created a Suite installer project, this installer contains some .exe packages. This exe packages is Installscript MSI projects. The first exe package has a service . I am passing the property value from suite installer to the individual packages as shown



Using this property value , if the value is "true", the Service should not start. If the property value is not equal to "true" the service should start as usual. .I have set the condition in InstallScript MSI project in Sequence where we have this service,as shown below



Thanks in advance
Labels (1)
0 Kudos
(5) Replies
sureshkottakki
Level 6

I there anyway that Suite installer can start/stop the services , and remove the start/stopping of services of its exe packages
0 Kudos
DLee65
Level 13

What happens if you change the case of the property to a PUBLIC PROPERTY. I suspect that the issue is that you are using a private property which cannot be passed in on a command line. Also look at your MSI log file because it lists what properties are passed in. But as I stated, you will find switching this to a public property will fix the issue.
0 Kudos
sureshkottakki
Level 6

Hi DLee65,
I tried to make it public and its working fine, but is there any way that Suite installer can start/stop the services , and remove the start/stopping of services of its exe packages
0 Kudos
DLee65
Level 13

Are you familiar with InstallScript? Add a custom InstallScript event to your suite. Below is what I used in 2013.

function Service_Start(szServiceName, szServiceArgs)
STRING szMsg;
begin
ServiceInitParams();
if (ServiceExistsService(szServiceName)!=TRUE) then
Sprintf ( szMsg , "Service_Start: WARNING - Service *%s* does not exist. Ignoring.....", szServiceName );
WriteMSILog(szMsg);
return 0;
endif;

if (ServiceStartService(szServiceName, szServiceArgs) Sprintf ( szMsg , "Service_Start: ERROR - Unable to start service *%s*!", szServiceName );
WriteMSILog(szMsg);
return -1;
endif;

Sprintf ( szMsg , "Service_Start: Service *%s* has been started successfully", szServiceName );
WriteMSILog(szMsg);
return 0;

end;


Note that I wrote mine for a basic MSI implementation but your implementation would be very similar.

If you are not comfortable with InstallScript, try another language that you like, C#, C++, vbscript, etc. I forget just how many other languages that they support for events in 2014, just look in the IS help for more information on what custom events you can use.
0 Kudos
DLee65
Level 13

I just found this code in one of my custom actions. This is a CLR project so .NET would be a requirement for this.
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
using System.IO;


namespace ModifyACServices
{
class Program
{


static void Main(string[] args)
{

string serviceCmd = args[0].ToUpper();
if (serviceCmd == "STOP")
{

StopService("AmazingChartsAdminService");
StopService("AmazingChartsService");
StopService("Amazing Charts Auth Service");
}
if (serviceCmd == "START")
{
StartService("AmazingChartsAdminService");
StartService("AmazingChartsService");
StartService("Amazing Charts Auth Service");
}
if (serviceCmd == "STOPSQL")
{
StopService("MSSQL$AMAZINGCHARTS");
}
if (serviceCmd == "STARTSQL")
{
StartService("MSSQL$AMAZINGCHARTS");
}
}

static void StopService(string pServiceName)
{
if (ServiceExists(pServiceName))
{
ServiceController service = new ServiceController(pServiceName);

if (service.Status.Equals(ServiceControllerStatus.Running))
{
try
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
service.Refresh();
}
catch (Exception e)
{
System.IO.File.WriteAllText(@"C:\Users\Public\InstallResults\ErrorReturn.txt", e.Message);
//If it fails we will not worry about it for the installer
}
}
}
}

static void StartService(string pServiceName)
{
if (ServiceExists(pServiceName))
{
ServiceController service = new ServiceController(pServiceName);
if (service.Status.Equals(ServiceControllerStatus.StopPending))
{
service.WaitForStatus(ServiceControllerStatus.Stopped);
service.Refresh();
}
if (service.Status.Equals(ServiceControllerStatus.Stopped))
{
try
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
service.Refresh();
}
catch
{
//Sometimes the service will just not start for some reason due to installation errors, but do not want install to hang so inserting try catch
}
}
}
}



static bool ServiceExists(string pServiceName)
{
try
{
ServiceController[] scServices;
scServices = ServiceController.GetServices();

foreach (ServiceController scTemp in scServices)
{
if (scTemp.ServiceName == pServiceName)
{
return true;
}
}

}
catch (Exception e)
{
System.IO.File.WriteAllText(@"C:\Users\Public\InstallResults\ErrorReturn.txt", e.Message);
}

return false;
}



}

}


[/CODE]

To implement this you would build your C# custom action.
Add the EXE to your suite project as an event file.
Add the Argument STOP | START | etc
This implementation will allow the suite to stop services for uninstall, or patching, etc. And then after the update, install is complete, then start services.
0 Kudos