Exemplo n.º 1
0
        private void UpdateService(WinServiceInstaller group)
        {
            try
            {
                var serviceKey = group.ServiceNamePrefix + ServiceName;

                Console.Write("Updating: {0}", serviceKey);

                var serviceController = GetWindowsService(serviceKey);

                /////// UPDATE
                if (serviceController != null)
                {
                    serviceController.DisplayName = DisplayName;

                    try
                    {
                        if (StartMode != GetServiceStart(serviceKey))
                        {
                            _SetServiceStart(serviceKey, StartMode);
                        }
                    }
                    catch (ApplicationException e)
                    {
                        Console.WriteLine("Exception: " + e);
                    }

                    Console.WriteLine(" Done.");

                    return;
                }

                Console.WriteLine(" Not Found.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e);
            }
        }
Exemplo n.º 2
0
        private void InstallService(WinServiceInstaller group)
        {
            try
            {
                var serviceKey = group.ServiceNamePrefix + ServiceName;

                Console.WriteLine("Installing: {0}", serviceKey);

                var serviceController = GetWindowsService(serviceKey);

                if (serviceController != null)
                {
                    Console.WriteLine(" Already Installed.");

                    return;
                }

                var installLogFile = Path.GetTempFileName();

                Console.WriteLine("Log: {0}", installLogFile);

                var context = new InstallContext(installLogFile, new[] { String.Format("/assemblypath={0}", Process.GetCurrentProcess().MainModule.FileName.Replace("vshost.", "")) });

                var runner = new Installer {
                    Context = context
                };

                var procesServiceInstaller = new ServiceProcessInstaller
                {
                    Context     = context,
                    Account     = ServiceAccount,
                    Username    = null,
                    Password    = null,
                    CmdLineArgs = new[] { String.Format("{0} {1}", HostApplication, serviceKey) }
                };

                var serviceInstallerObj = new ServiceInstaller
                {
                    Context            = context,
                    DisplayName        = DisplayName,
                    Description        = Description,
                    ServiceName        = serviceKey,
                    ServicesDependedOn = default(string[]),
                    StartType          = StartMode,
                    StartOnInstall     = false,
                    FailRunCommand     = FailureRunCommand
                };

                if (FirstFailureAction != null)
                {
                    serviceInstallerObj.FailureActions.Add(FirstFailureAction);
                }
                if (SecondFailureAction != null)
                {
                    serviceInstallerObj.FailureActions.Add(SecondFailureAction);
                }
                if (SubsequentFailuresAction != null)
                {
                    serviceInstallerObj.FailureActions.Add(SubsequentFailuresAction);
                }

                serviceInstallerObj.FailCountResetTime = default(int);             // 1 dia.

                runner.Installers.Add(procesServiceInstaller);
                runner.Installers.Add(serviceInstallerObj);

                var state = new ListDictionary();

                try
                {
                    runner.Install(state);
                    runner.Commit(state);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception: " + e);
                    runner.Rollback(state);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e);
            }
        }
Exemplo n.º 3
0
        internal static void InstallAllServices(bool AutomaticUninstall, bool Purge, bool AutomaticInstall, bool AutomaticUpdate, String ServiceNamePrefix, IEnumerable <WinService> winServicesToInstall, WinServiceInstaller parent)
        {
            if (AutomaticUninstall)
            {
                UninstallUndefined(ServiceNamePrefix, Purge, winServicesToInstall);
            }

            foreach (var winService in winServicesToInstall)
            {
                if (AutomaticInstall)
                {
                    winService.InstallService(parent);
                }
                if (AutomaticUpdate)
                {
                    winService.UpdateService(parent);
                }
            }
        }