public AsimovTask GetUninstallTask()
 {
     return(new PowershellUninstallTask(
                Installable,
                this,
                new Dictionary <string, object>()
     {
         { "ServiceName", ServiceName }
     })
     {
         TargetPath = WindowsServiceUtil.GetWindowsServicePath(ServiceName)
     });
 }
        public void Execute(DeployContext context)
        {
            var deployUnit = (WindowsServiceDeployUnit)context.DeployUnit;

            using (var controller = new ServiceController(deployUnit.ServiceName))
            {
                StopService(context, controller);

                context.PhysicalPath = WindowsServiceUtil.GetWindowsServicePath(deployUnit.ServiceName);

                CleanPhysicalPath(context);

                CopyNewFiles(context);

                context.Log.InfoFormat("Starting service {0}", deployUnit.ServiceName);
                controller.Start();

                controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(1));
            }
        }
        public void Execute(DeployContext context)
        {
            var deployUnit = (WindowsServiceDeployUnit)context.DeployUnit;

            using (var controller = new ServiceController(deployUnit.ServiceName))
            {
                StopService(context, controller);

                context.PhysicalPath = WindowsServiceUtil.GetWindowsServicePath(deployUnit.ServiceName);

                CleanPhysicalPath(context);

                CopyNewFiles(context);

                context.Log.InfoFormat("Starting service {0}", deployUnit.ServiceName);
                try
                {
                    controller.Start();
                }
                catch (InvalidOperationException invalidOpEx)
                {
                    var win32Exception = invalidOpEx.InnerException as Win32Exception;
                    if (win32Exception != null && win32Exception.NativeErrorCode == ERROR_SERVICE_ALREADY_RUNNING)
                    {
                        context.Log.InfoFormat("Service {0} was already running. Continuing.", deployUnit.ServiceName);
                    }
                    else
                    {
                        throw;
                    }
                }

                if (!context.ParameterValues.HasValue("SkipWaitForServiceStart", true))
                {
                    controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(1));
                }
            }
        }