Our installation process includes a Windows Service which is installed if our software is configured to be installed as a server (vs. a client installation). I added a service library to be able to manage the services, then in the files, I added handlers for BeforeInstall
and AfterInstall
events...
[Files]
Source: "MyService.exe"; DestDir: "{app}"; Check: IsServer; BeforeInstall: BeforeServiceInstall('MyServiceName', 'MyService.exe'); AfterInstall: AfterServiceInstall('MyServiceName', 'MyService.exe')
procedure BeforeServiceInstall(SvcName, FileName: String);
var
S: Longword;
begin
//If service is installed, it needs to be stopped
if ServiceExists(SvcName) then begin
S:= SimpleQueryService(SvcName);
if S <> SERVICE_STOPPED then begin
SimpleStopService(SvcName, True, True);
end;
end;
end;
procedure AfterServiceInstall(SvcName, FileName: String);
begin
//If service is not installed, it needs to be installed now
if not ServiceExists(SvcName) then begin
if SimpleCreateService(SvcName, 'My Service Name', ExpandConstant('{app}')+'\' + FileName, SERVICE_AUTO_START, '', '', False, True) then begin
//Service successfully installed
SimpleStartService(SvcName, True, True);
end else begin
//Service failed to install
end;
end;
end;
When installing the service for the first time (doesn't already exist and isn't currently running), the installation/starting of this service works just fine. However, when running this installer on an existing installation (upgrade), the installer stops when it recognizes that this service is running, and prompts to terminate the process (before it calls the BeforeServiceInstall()
handler)...
How do I prevent this prompt from appearing for services? I'm avoiding having to require a restart and would still like this prompt to appear for all other files.