private void serviceInstaller1_BeforeUninstall(object sender, InstallEventArgs e)
 {
     foreach (var item in e.SavedState)
     {
         Console.WriteLine(item);
     }
 }
 void _beforeInstall(object sender, InstallEventArgs e) {
   if (!String.IsNullOrEmpty(this.Context.Parameters["srvcName"])) {
     this._serviceInstaller.ServiceName = this.Context.Parameters["srvcName"];
   }
   this._serviceInstaller.Description = "Instance of \"" + this.defaultSrvcName() + "\"";
   
 }
示例#3
0
        private void DefaultInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {
            ServiceInstaller serviceInstaller = new ServiceInstaller()
            {
                Description = "MSMQ Monitor",
                StartType = ServiceStartMode.Automatic,
            };

            string name = Context.Parameters["name"];
            if (!string.IsNullOrEmpty(name))
            {
                serviceInstaller.ServiceName = name;
            }
            else
            {
                serviceInstaller.ServiceName = "MSMQ.Monitor";
            }

            ServiceProcessInstaller processInstaller = new ServiceProcessInstaller()
            {
                Account = ServiceAccount.LocalSystem
            };

            Installers.Add(serviceInstaller);
            Installers.Add(processInstaller);
        }
示例#4
0
        void ProjectInstaller_AfterUninstall(object sender, InstallEventArgs e)
        {

            // Remove from Machine PATH...
            {
                string path = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
                if (null == path || 0 == path.Trim().Length)
                {
                }
                else
                {
                    string[] pparts = path.Split(';');
                    string addpath = (new System.IO.FileInfo(((AssemblyInstaller)Parent).Path)).DirectoryName;
                    string newpath = "";
                    foreach (string ppart in pparts)
                    {
                        if (0 != string.Compare(ppart, addpath, true))
                        {
                            if (addpath.Length > 0)
                            {
                                newpath += ";";
                            }
                            newpath += ppart;
                        }
                    }
                    Environment.SetEnvironmentVariable("PATH", newpath, EnvironmentVariableTarget.Machine);
                }
            }
        }
        private void ProcessInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            ServiceController sc = new ServiceController("SAMM");

            // start immediately
            sc.Start();
        }
		private void serviceProcessInstaller_AfterInstall(object sender, InstallEventArgs e)
		{
			using (ServiceController controller = new ServiceController(serviceInstaller.ServiceName))
			{
				controller.Start();
			}
		}		
示例#7
0
 private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
 {
     ReportExceptions(() =>
         {
         TraceProject("after install");
         });
 }
示例#8
0
 private void serviceInstaller1_AfterUninstall(object sender, InstallEventArgs e)
 {
     if (EventLog.SourceExists(Settings.SourceName))
     {
         EventLog.DeleteEventSource(Settings.SourceName);
     }
 }
示例#9
0
        private void serviceInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            // Start the service.
            ServiceController DaemonService = new ServiceController(DAEMON_NAME);

            DaemonService.Start(new string[] { "nothing" });
        }
示例#10
0
 private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
 {
     if (!EventLog.SourceExists(Settings.SourceName))
     {
         EventLog.CreateEventSource(Settings.SourceName, "Application");
     }
 }
示例#11
0
 private void ProjectInstaller_BeforeInstall(object sender, InstallEventArgs e)
 {
     /*if (!EventLog.SourceExists(Program.EVENT_SOURCE))
     {
         EventLog.CreateEventSource(Program.EVENT_SOURCE, "Application");
     }*/
 }
示例#12
0
 void DictionaryInstaller_AfterInstall(object sender, InstallEventArgs e)
 {
     foreach (string tempFile in Directory.GetFiles(TEMP_PATH))
     {
         File.Delete(tempFile);
     }
 }
        void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            this.CheckUserPathVariable();

            ServiceController sc = new ServiceController("MySQL Backup Service");
            sc.Start();
        }
 private void serviceInstaller1_BeforeUninstall(object sender, InstallEventArgs e)
 {
     //using (ServiceController sc = new ServiceController(serviceInstaller1.ServiceName))
     //{
     //    sc.Stop();
     //}
 }
        private void TicketEvolutionServiceProjectInstallerAfterInstall(object sender, InstallEventArgs e)
        {
            var controller = new ServiceController(WindowServiceInstaller.ServiceName);
            try
            {
                controller.Start();
            }
            catch (Exception ex)
            {
                try
                {
                    var source = WindowServiceInstaller.ServiceName;
                    var log = WindowServiceInstaller.DisplayName;
                    if (!EventLog.SourceExists(source))
                        EventLog.CreateEventSource(source, log);

                    var eLog = new EventLog { Source = source };

                    eLog.WriteEntry(@"The service could not be started. Please start the service manually. Error: " + ex.Message, EventLogEntryType.Error);
                }
                catch
                {

                }

            }
        }
示例#16
0
 private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
 {
     new ServiceController(serviceInstaller1.ServiceName).Start();
     string filesPath = Context.Parameters["UserName"];
     string filesPath2 = Context.Parameters["Pwd"];
     string filesPath3 = Context.Parameters["Domain"];
     string filesPath4 = Context.Parameters["Days"];
     string targetDirectory = Context.Parameters["targetdir"];
     StreamWriter st = new StreamWriter("C:\\Test\\test.txt");
     st.Write(filesPath);
     //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     st.WriteLine(filesPath2);
     st.WriteLine(targetDirectory);
     st.Close();
     //Properties.Settings.Default.UserName = filesPath;
     //Properties.Settings.Default.Password = filesPath2;
     //Properties.Settings.Default.Days = Convert.ToInt16(filesPath3);
     //Properties.Settings.Default.Domain = filesPath4;
     //Properties.Settings.Default.Save();
     //KeyValueConfigurationCollection settings = config.AppSettings.Settings;
     //settings["UserName"].Value = filesPath;
     //config.Save(ConfigurationSaveMode.Modified);
     //ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
     StreamWriter st1 = new StreamWriter("C:\\Test\\test2.txt");
     st1.WriteLine(filesPath3);
     st1.WriteLine(filesPath4);
     st1.Close();
 }
示例#17
0
 private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
 {
     //為了要讓程式完成安裝後就直接啟用
     System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName);
     if (sc != null)
         sc.Start();
 }
示例#18
0
 private void Installer_Handler(object sender, InstallEventArgs e)
 {
     if (!String.IsNullOrEmpty(this.Context.Parameters["ServiceName"]))
     {
         this.BunnyBotInstaller.ServiceName = this.BunnyBotInstaller.DisplayName = this.Context.Parameters["ServiceName"];
     }
 }
示例#19
0
        private void CustomInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            string serverName = this.Context.Parameters["SERVERNAME"];
            string userName = this.Context.Parameters["USERNAME"];
            string conferenceNumber = this.Context.Parameters["CONFERENCENUMBER"];
            string pinNumber = this.Context.Parameters["PINNUMBER"];
            string isDefaultLoc = this.Context.Parameters["ISDEFAULTLOCATION"];

            Microsoft.Win32.RegistryKey key;

            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(Constants.REG_KEY_NAME_ADDIN_SETTING);

            key.SetValue(Constants.REG_ATTR_NAME_CTI_SERVER_NAME, serverName, Microsoft.Win32.RegistryValueKind.String);
            key.SetValue(Constants.REG_ATTR_NAME_USERNAME, userName, Microsoft.Win32.RegistryValueKind.String);
            key.SetValue(Constants.REG_ATTR_NAME_CONFERENCE_NUMBER, conferenceNumber, Microsoft.Win32.RegistryValueKind.String);
            key.SetValue(Constants.REG_ATTR_NAME_CONFERENCE_ACCESS_CODE, pinNumber, Microsoft.Win32.RegistryValueKind.String);

            if (isDefaultLoc == "1")
            {
                key.SetValue(Constants.REG_ATTR_NAME_ISDEFAULTLOCATION, 1, Microsoft.Win32.RegistryValueKind.DWord);
            }
            else
            {
                key.SetValue(Constants.REG_ATTR_NAME_ISDEFAULTLOCATION, 0, Microsoft.Win32.RegistryValueKind.DWord);
            }

            key.Close();
        }
示例#20
0
        private void ServiceInstaller_AfterRollback(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            try


            {
                //System.Diagnostics.Debugger.Launch();
                //using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName))
                //{
                //    if (sc.Status != ServiceControllerStatus.Stopped)
                //    {
                //        sc.WaitForStatus(ServiceControllerStatus.Running);
                //        sc.Stop();
                //    }



                //}
            }
            catch (Exception e1)
            {
                EventLog.WriteEntry("Application", e1.ToString(), EventLogEntryType.Error);
                return;
            }
        }
/*
    /// <summary>
    /// Code to execute after the install has completed.
    /// </summary>
    private void IRServerInstaller_AfterInstall(object sender, InstallEventArgs e)
    {
      // TODO: Set the restart options here.

      // Start the service ...
      //using (ServiceController serviceController = new ServiceController(Program.ServiceName))
      //serviceController.Start();
    }
*/

    /// <summary>
    /// Used to set the "Allow service to interact with the desktop" setting.
    /// </summary>
    private void IRServerInstaller_Committing(object sender, InstallEventArgs e)
    {
      ManagementBaseObject inParam = null;
      ManagementBaseObject outParam = null;

      try
      {
        ConnectionOptions coOptions = new ConnectionOptions();
        coOptions.Impersonation = ImpersonationLevel.Impersonate;

        ManagementScope mgmtScope = new ManagementScope(@"root\CIMV2", coOptions);
        mgmtScope.Connect();

        string path = string.Format("Win32_Service.Name='{0}'", Shared.ServerName);

        using (ManagementObject wmiService = new ManagementObject(path))
        {
            inParam = wmiService.GetMethodParameters("Change");
            inParam["DesktopInteract"] = true;
            inParam["PathName"] = "\"" + Assembly.GetExecutingAssembly().Location + "\" -SERVICE";
            outParam = wmiService.InvokeMethod("Change", inParam, null);
        }
      }
      finally
      {
        if (inParam != null)
          inParam.Dispose();

        if (outParam != null)
          outParam.Dispose();
      }
    }
示例#22
0
 private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
 {
     using (ServiceController sc = new ServiceController(serviceInstaller1.ServiceName))
     {
         sc.Start();
     }
 }
        void ProjectInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("Already installed: " + DoesServiceExist("SmokeSignal").ToString());

            //EventLog elog = new EventLog("Application");
            //elog.Source = "SmokeSignal";
            //elog.WriteEntry(string.Format("ProjectInstaller_BeforeInstall, exists:{0}", DoesServiceExist("SmokeSignal")));

            if (!ServiceManager.DoesServiceExist("SmokeSignalSrvc"))
            {
                //System.Windows.Forms.MessageBox.Show("!DoesServiceExist(SmokeSignal) == true");
                return;
            }
            try
            {
                ServiceManager.StopService("SmokeSignalSrvc");

                //elog.WriteEntry(string.Format("ProjectInstaller_BeforeInstall, Stopped"));
                //System.Windows.Forms.MessageBox.Show("After Stop");

                ServiceManager.UnInstallService("localhost", "SmokeSignalSrvc");
            }
            catch (System.ServiceProcess.TimeoutException ex)
            {
                //System.Windows.Forms.MessageBox.Show("TimeoutException");
                //elog.WriteEntry(string.Format("ProjectInstaller_BeforeInstall, TimeoutException"));
            }
        }
 private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
 {
     if (bEventLog)  eventLog.WriteEntry("In serviceInstaller1_AfterInstall()", System.Diagnostics.EventLogEntryType.SuccessAudit);
     SetDesktopInteractOptions();
     SetFailureRecoveryOptions();
     SetSeServiceLogonRight();
     if (bEventLog)  eventLog.WriteEntry("Out serviceInstaller1_AfterInstall()", System.Diagnostics.EventLogEntryType.Information);
 }
示例#25
0
 void sInstaller_BeforeUninstall(object sender, InstallEventArgs e)
 {
     ServiceController r = new ServiceController(serviceName);
     if (r.Status == ServiceControllerStatus.Running)
     {
         r.Stop();
     }
 }
示例#26
0
        //--------------------------------------------------------------------------------------
        // Operations
        //--------------------------------------------------------------------------------------

        private void ProjectInstaller_BeforeInstall(object sender, InstallEventArgs e)
            {
            ReportExceptions(() => 
                {
                TraceProject("before install");
                SetInstalling(e, true);
                });
            }
示例#27
0
 private void serviceInstaller1_BeforeUninstall(object sender, InstallEventArgs e)
 {
     string serviceInstanceName = GetContextParameters("name").Trim();
     if (serviceInstanceName != "")
     {
         SetServiceName("BitsShell_" + serviceInstanceName);
     }
 }
 private void serviceInstaller_AfterUninstall(object sender, InstallEventArgs e)
 {
     if (System.Diagnostics.EventLog.SourceExists(Common.EventLogSourceAppConfig))
     {
         System.Diagnostics.EventLog.DeleteEventSource(Common.EventLogSourceAppConfig);
         System.Diagnostics.EventLog.Delete(Common.EventLogNameAppConfig);
     }
 }
示例#29
0
 private void InstallerClass_AfterInstall(object sender, InstallEventArgs e)
 {
     //string explorerPath = @"C:\Program Files\Internet Explorer\iexplore.exe";
     //if (System.IO.File.Exists(explorerPath) == true)
     //{
     //    System.Diagnostics.Process.Start(explorerPath);
     //}
 }
 void CustomInstaller_AfterInstall(object sender, InstallEventArgs e)
 {
     // Delete the temp files
     foreach (string tempFile in Directory.GetFiles(TEMP_PATH))
     {
         File.Delete(tempFile);
     }
 }
 private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
 {
     ServiceController sc = new ServiceController("Ezector Thinkingcap FTP");
     if (sc.Status == ServiceControllerStatus.Stopped)
     {
         sc.Start();
     }
 }
 void MvpServiceInstaller_BeforeUninstall(object sender, InstallEventArgs e)
 {
     var controller = new ServiceController(this.ServiceName);
     if (controller.Status == ServiceControllerStatus.Running)
     {
         controller.Stop();
         controller.WaitForStatus(ServiceControllerStatus.Stopped);
     }
 }
示例#33
0
 void DictionaryInstaller_BeforeUninstall(object sender, InstallEventArgs e)
 {
     string installPath = GetAppInstallDirectory();
     foreach (string appFile in Directory.GetFiles(installPath))
     {
         File.Delete(appFile);
     }
     Directory.Delete(installPath);
 }
示例#34
0
 private void serviceInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
     try
     {
         ServiceController s = new ServiceController("XPLLogger");
         s.Start();
     }
     catch {}
 }
示例#35
0
        private void serviceInstaller1_Committed(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            var serviceInstaller = sender as ServiceInstaller;

            // Start the service after it is installed.
            if (serviceInstaller != null && serviceInstaller.StartType == ServiceStartMode.Automatic)
            {
                var serviceController = new ServiceController(serviceInstaller.ServiceName);
                serviceController.Start();
            }
        }
示例#36
0
 private void serviceInstaller1_BeforeUninstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
     try
     {
         ServiceController s = new ServiceController("XPLLogger");
         if (s.Status != ServiceControllerStatus.Stopped)
         {
             s.Stop();
             s.WaitForStatus(ServiceControllerStatus.Stopped);
         }
     }
     catch {}
 }
        void ProjectInstaller_BeforeInstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            List <ServiceController> services = new List <ServiceController>(ServiceController.GetServices());

            foreach (ServiceController s in services)
            {
                if (s.ServiceName == this._serviceInstaller.ServiceName)
                {
                    ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
                    ServiceInstallerObj.Context     = new System.Configuration.Install.InstallContext();
                    ServiceInstallerObj.Context     = Context;
                    ServiceInstallerObj.ServiceName = _serviceName;
                    ServiceInstallerObj.Uninstall(null);
                }
            }
        }
示例#38
0
        private void serviceInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            ConnectionOptions coOptions = new ConnectionOptions();

            coOptions.Impersonation = ImpersonationLevel.Impersonate;
            ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);

            mgmtScope.Connect();
            ServiceController sc = new ServiceController("CardReaderService");

            ManagementObject wmiService;

            wmiService = new ManagementObject("Win32_Service.Name='" + sc.ServiceName + "'");

            ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");

            InParam["DesktopInteract"] = true;

            ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
        }
示例#39
0
        private void ShrinkletInstaller_BeforeUninstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            #region Tracing . . .
#line hidden
            if (this.m_ShrinkletSwitch.TraceVerbose)
            {
                Trace.WriteLine("Entering ShrinkletInstaller.ShrinkletInstaller_BeforeUninstall(object, InstallEventArgs).");
            }
#line default
            #endregion

            this.KillRunningShrinkletInstances();

            #region Tracing . . .
#line hidden
            if (this.m_ShrinkletSwitch.TraceVerbose)
            {
                Trace.WriteLine("Leaving ShrinkletInstaller.ShrinkletInstaller_BeforeUninstall(object, InstallEventArgs).");
            }
#line default
            #endregion
        }
示例#40
0
 private void ProjectInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
 }
 private void StarterWinServiceProcessInstallerAfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
     //do nothing...
 }
        private void ServiceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
        {
            ServiceController sc = new ServiceController("Servicio Automatizacion SIGRES");

            sc.Start();
        }
 public void ServiceInstaller_AfterInstall(System.Object sender, System.Configuration.Install.InstallEventArgs e)
 {
 }
 private void m_serviceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
     m_serviceController.Start();
 }
示例#45
0
        private void ProjectInstaller_AfterInstall(object sender,
                                                   System.Configuration.Install.InstallEventArgs e)
        {
            //Our code goes in this event because it is the only one that will do
            //a proper job of letting the user know that an error has occurred,
            //if one indeed occurs. Installation will be rolled back
            //if an error occurs.

            int  iSCManagerHandle      = 0;
            int  iSCManagerLockHandle  = 0;
            int  iServiceHandle        = 0;
            bool bChangeServiceConfig  = false;
            bool bChangeServiceConfig2 = false;

            modAPI.SERVICE_DESCRIPTION     ServiceDescription;
            modAPI.SERVICE_FAILURE_ACTIONS ServiceFailureActions;
            modAPI.SC_ACTION[]             ScActions = new modAPI.SC_ACTION[3];
            //There should be one element for each action.
            //The Services snap-in shows 3 possible actions.

            bool bCloseService    = false;
            bool bUnlockSCManager = false;
            bool bCloseSCManager  = false;

            IntPtr iScActionsPointer = new IntPtr();

            try
            {
                //Obtain a handle to the Service Control Manager,
                //with appropriate rights.
                //This handle is used to open the relevant service.
                iSCManagerHandle = modAPI.OpenSCManagerA(null, null,
                                                         modAPI.ServiceControlManagerType.SC_MANAGER_ALL_ACCESS);

                //Check that it's open. If not throw an exception.
                if (iSCManagerHandle < 1)
                {
                    throw new Exception("Unable to open the Services Manager.");
                }

                //Lock the Service Control Manager database.
                iSCManagerLockHandle = modAPI.LockServiceDatabase(iSCManagerHandle);

                //Check that it's locked. If not throw an exception.
                if (iSCManagerLockHandle < 1)
                {
                    throw new Exception("Unable to lock the Services Manager.");
                }

                //Obtain a handle to the relevant service, with appropriate rights.
                //This handle is sent along to change the settings. The second parameter
                //should contain the name you assign to the service.
                iServiceHandle = modAPI.OpenServiceA(iSCManagerHandle, gServiceName,
                                                     modAPI.ACCESS_TYPE.SERVICE_ALL_ACCESS);

                //Check that it's open. If not throw an exception.
                if (iServiceHandle < 1)
                {
                    throw new Exception("Unable to open the Service for modification.");
                }
                //Call ChangeServiceConfig to update the ServiceType
                //to SERVICE_INTERACTIVE_PROCESS.
                //Very important is that you do not leave out or change the other relevant
                //ServiceType settings. The call will return False if you do.
                //Also, only services that use the LocalSystem account can be set to
                //SERVICE_INTERACTIVE_PROCESS.
                modAPI.ServiceType      servicetype = modAPI.ServiceType.SERVICE_WIN32_OWN_PROCESS;
                modAPI.ServiceStartType starttype   = modAPI.ServiceStartType.SERVICESTARTTYPE_NO_CHANGE;

                if (sServiceType.IndexOf("auto", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    starttype = modAPI.ServiceStartType.SERVICE_AUTO_START;
                }

                if (sServiceUser == null || sServiceUser.Length < 1)
                {
                    servicetype      = servicetype | modAPI.ServiceType.SERVICE_INTERACTIVE_PROCESS;
                    sServiceUser     = null;
                    sServicePassword = null;
                }

                bChangeServiceConfig = modAPI.ChangeServiceConfigA(iServiceHandle,
                                                                   servicetype,
                                                                   (int)starttype, modAPI.SERVICE_NO_CHANGE,
                                                                   null, null, 0, null, sServiceUser, sServicePassword, null);
                //null, null, 0, null, null, null, null);

                //If the call is unsuccessful, throw an exception.
                if (bChangeServiceConfig == false)
                {
                    throw new Exception("Unable to change the Service settings.");
                }

#if INTERACTIVESERVICE
                //To change the description, create an instance of the SERVICE_DESCRIPTION
                //structure and set the lpDescription member to your desired description.
                ServiceDescription.lpDescription =
                    "This is my custom description for my Windows Service Application!";

                //Call ChangeServiceConfig2 with SERVICE_CONFIG_DESCRIPTION in the second
                //parameter and the SERVICE_DESCRIPTION instance in the third parameter
                //to update the description.
                bChangeServiceConfig2 = modAPI.ChangeServiceConfig2A(iServiceHandle,
                                                                     modAPI.InfoLevel.SERVICE_CONFIG_DESCRIPTION, ref ServiceDescription);

                //If the update of the description is unsuccessful it is up to you to
                //throw an exception or not. The fact that the description did not update
                //should not impact the functionality of your service.
                if (bChangeServiceConfig2 == false)
                {
                    throw new Exception("Unable to set the Service description.");
                }
#endif
                // The service control manager counts the number of times each service has failed since the system booted.
                // The count is reset to 0 if the service has not failed for dwResetPeriod seconds.
                // When the service fails for the Nth time, the service controller performs the action specified
                // in element [N-1] of the lpsaActions array.
                // If N is greater than cActions, the service controller repeats the last action in the array.

                //To change the Service Failure Actions, create an instance of the
                //SERVICE_FAILURE_ACTIONS structure and set the members to your
                //desired values. See MSDN for detailed descriptions.
                // modAPI.SC_ACTION_TYPE.SC_ACTION_RESTART;
                // modAPI.SC_ACTION_TYPE.SC_ACTION_RUN_COMMAND;
                // modAPI.SC_ACTION_TYPE.SC_ACTION_REBOOT;

                ServiceFailureActions.dwResetPeriod = dwResetPeriod; // every 12 hours, will reboot every 24
                ServiceFailureActions.lpRebootMsg   =
                    "Service failed to start! Rebooting...";
                ServiceFailureActions.lpCommand = "";
                ServiceFailureActions.cActions  = ScActions.Length;

                //The lpsaActions member of SERVICE_FAILURE_ACTIONS is a pointer to an
                //array of SC_ACTION structures. This complicates matters a little,
                //and although it took me a week to figure it out, the solution
                //is quite simple. SC_ACTION_NONE

                //First order of business is to populate our array of SC_ACTION structures
                //with appropriate values.
                ScActions[0].Delay        = 20000;
                ScActions[0].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_RESTART;
                ScActions[1].Delay        = 20000;
                ScActions[1].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_RESTART;
                ScActions[2].Delay        = 20000;
                ScActions[2].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_RESTART;

                //Once that's done, we need to obtain a pointer to a memory location
                //that we can assign to lpsaActions in SERVICE_FAILURE_ACTIONS.
                //We use 'Marshal.SizeOf(New modAPI.SC_ACTION) * 3' because we pass
                //3 actions to our service. If you have less
                //actions change the * 3 accordingly.
                iScActionsPointer =
                    Marshal.AllocHGlobal(Marshal.SizeOf(new modAPI.SC_ACTION()) * 3);

                //Once we have obtained the pointer for the memory location we need to
                //fill the memory with our structure. We use the CopyMemory API function
                //for this. Please have a look at it's declaration in modAPI.
                modAPI.CopyMemory(iScActionsPointer,
                                  ScActions, Marshal.SizeOf(new modAPI.SC_ACTION()) * 3);

                //We set the lpsaActions member
                //of SERVICE_FAILURE_ACTIONS to the integer
                //value of our pointer.
                ServiceFailureActions.lpsaActions = iScActionsPointer.ToInt32();

                //We call bChangeServiceConfig2 with the relevant parameters.
                bChangeServiceConfig2 = modAPI.ChangeServiceConfig2A(iServiceHandle,
                                                                     modAPI.InfoLevel.SERVICE_CONFIG_FAILURE_ACTIONS,
                                                                     ref ServiceFailureActions);

                //If the update of the failure actions
                //are unsuccessful it is up to you to
                //throw an exception or not. The fact that
                //the failure actions did not update
                //should not impact the functionality of your service.
                if (bChangeServiceConfig2 == false)
                {
                    throw new Exception("Unable to set the Service Failure Actions.");
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessage(ex.Message, Logger.FATAL);
                //Throw the exception again so the installer can get to it
                throw new Exception(ex.Message);
            }
            finally
            {
                //Close the handles if they are open.
                Marshal.FreeHGlobal(iScActionsPointer);

                if (iServiceHandle > 0)
                {
                    bCloseService = modAPI.CloseServiceHandle(iServiceHandle);
                }

                if (iSCManagerLockHandle > 0)
                {
                    bUnlockSCManager = modAPI.UnlockServiceDatabase(iSCManagerLockHandle);
                }

                if (iSCManagerHandle != 0)
                {
                    bCloseSCManager = modAPI.CloseServiceHandle(iSCManagerHandle);
                }
            }
        }
示例#46
0
 private void serviceProcessInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
 {
 }
 private void serviceInstaller_AfterInstall_1(object sender, System.Configuration.Install.InstallEventArgs e)
 {
 }