On Wed, 10 Nov 2010 06:59:35 -0800 (PST), Lothar Behrens
<(E-Mail Removed)> wrote:
>Hi,
>
>I have written a windows service that could be installed and
>uninstalled without problems (including startup of the service). But
>when I try to update the components by a newer version the installer
>complains about that the service is installed and rolls back.
>
>The installer class looks like this and the last function was my
>second attempt to stop the service to avoid a message that an
>application must be stopped before updating. This is no problem as I
>am doing a silent install.
>
>How to overcome the installed service problem without writing two
>different installers?
>
>Is the BeforeInstall handler the right starting point to get rid of
>the second problem?
>(But probably missing a wait for stopping)
>
>Thanks, Lothar
>
> private void InitializeComponent()
> {
> this.MonitoringServiceProcessInstaller = new
>System.ServiceProcess.ServiceProcessInstaller();
> this.MonitoringServiceInstaller = new
>System.ServiceProcess.ServiceInstaller();
> this.serviceController1 = new
>System.ServiceProcess.ServiceController();
> //
> // MonitoringServiceProcessInstaller
> //
> this.MonitoringServiceProcessInstaller.Account =
>System.ServiceProcess.ServiceAccount.LocalSystem;
> this.MonitoringServiceProcessInstaller.Password = null;
> this.MonitoringServiceProcessInstaller.Username = null;
> //
> // MonitoringServiceInstaller
> //
> this.MonitoringServiceInstaller.ServiceName = "MyService";
> this.MonitoringServiceInstaller.StartType =
>System.ServiceProcess.ServiceStartMode.Automatic;
> //
> // serviceController1
> //
> this.serviceController1.ServiceName = "MyService";
> //
> // SMCMonitoringInstaller
> //
> this.Installers.AddRange(new
>System.Configuration.Install.Installer[] {
> this.MonitoringServiceProcessInstaller,
> this.MonitoringServiceInstaller});
> this.BeforeUninstall += new
>System.Configuration.Install.InstallEventHandler(this.SMCMonitoringInstaller_BeforeUninstall);
> this.BeforeInstall += new
>System.Configuration.Install.InstallEventHandler(this.SMCMonitoringInstaller_BeforeInstall);
> this.AfterInstall += new
>System.Configuration.Install.InstallEventHandler(this.SMCMonitoringInstaller_AfterInstall);
>
> }
>
> private void SMCMonitoringInstaller_AfterInstall(object
>sender, InstallEventArgs e)
> {
> serviceController1.Start();
> }
>
> private void SMCMonitoringInstaller_BeforeUninstall(object
>sender, InstallEventArgs e)
> {
> serviceController1.Stop();
> }
>
> private void SMCMonitoringInstaller_BeforeInstall(object
>sender, InstallEventArgs e)
> {
> try
> {
> serviceController1.Stop();
> }
> catch
> {
>
> }
> }
What if you try uninstalling the older service, not just stopping it?
|