title: Inno Setup - properly stop service before file copy
body: <p>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 href="http://www.sandon.it/files/services_unicode.iss" rel="noreferrer">a service library</a> to be able to manage the services, then in the files, I added handlers for <code>BeforeInstall</code> and <code>AfterInstall</code> events...</p>
  
  <pre><code>[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 &lt;&gt; 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;
  </code></pre>
  
  <p>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 (<em>before</em> it calls the <code>BeforeServiceInstall()</code> handler)...</p>
  
  <p><img src="https://i.stack.imgur.com/NRXKK.png" alt="Prompt message"></p>
  
  <p>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.</p>