コード例 #1
0
        /// <summary>
        /// Method OnWindowsServiceInstallerCommitted.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Instance of InstallEventArgs.</param>
        private void OnWindowsServiceInstallerCommitted(object sender, InstallEventArgs e)
        {
            if (this.InstallerSetupInfo.RestartOnFailure)
            {
                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(Environment.SystemDirectory, "cmd.exe"));
                    startInfo.Arguments       = string.Format(" /C {0}", string.Format("sc failure \"{0}\" reset= 60 actions= restart/300000", this.InstallerSetupInfo.ServiceName));
                    startInfo.CreateNoWindow  = true;
                    startInfo.ErrorDialog     = false;
                    startInfo.UseShellExecute = true;
                    startInfo.Verb            = "runas";
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    Process process = Process.Start(startInfo);

                    if (process.WaitForExit(5000))
                    {
                        process.Dispose();
                    }
                }
                catch
                {
                }
            }

            if (this.InstallerSetupInfo.StartAfterInstall)
            {
                WindowsServiceBase.Start(this.InstallerSetupInfo.ServiceName);
            }
        }
コード例 #2
0
 /// <summary>
 /// Method Uninstall.
 /// </summary>
 private void Uninstall()
 {
     if (WindowsServiceBase.ServiceExists(this._setupInfo.ServiceName))
     {
         WindowsServiceInstaller.RuntimeUninstall(this._setupInfo);
     }
     else
     {
         this.WriteToConsole(ConsoleColor.Red, "The specified service does not exist as an installed service.", true, false);
     }
 }
コード例 #3
0
 /// <summary>
 /// Method Install.
 /// </summary>
 private void Install()
 {
     if (!WindowsServiceBase.ServiceExists(this._setupInfo.ServiceName))
     {
         WindowsServiceInstaller.RuntimeInstall(this._setupInfo);
     }
     else
     {
         this.WriteToConsole(ConsoleColor.Red, "The specified service already exists.", true, false);
     }
 }
コード例 #4
0
 /// <summary>
 /// Method WriteCommandInfo.
 /// </summary>
 private void WriteCommandInfo()
 {
     this.WriteToConsole(ConsoleColor.White, string.Format("[O]riginal: {0}", this._windowsService.ServiceSetupInfo.ServiceName).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, string.Format("[N]ame:     {0}", this._setupInfo.ServiceName).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, string.Format("Mode:       {0}", this.IsConsoleMode ? "Console" : "Service").PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, string.Format("Status:     {0}", this.IsConsoleMode ? this._consoleStatus : this.ServiceStatus).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, string.Format("Installed:  {0}", WindowsServiceBase.ServiceExists(this._setupInfo.ServiceName)).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, " ".PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, "[S]tart       S[t]op        [P]ause       [R]esume      R[e]start     ", true, false);
     this.WriteToConsole(ConsoleColor.White, string.Format("{0}[I]nstall     [U]ninstall   St[a]tus      [Q]uit        ", this.IsConsoleMode ? "Ser[v]ice     " : "[C]onsole     "), true, false);
     this.WriteToConsole(ConsoleColor.White, " ".PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.White, "Enter:", false, false);
 }
コード例 #5
0
        /// <summary>
        /// Method Resume.
        /// </summary>
        private void Resume()
        {
            ServiceControllerStatus originalConsoleStatus = this._consoleStatus;

            if (this.IsConsoleMode)
            {
                if (this._consoleStatus == ServiceControllerStatus.Paused)
                {
                    this._consoleStatus = ServiceControllerStatus.ContinuePending;
                    this.WriteToConsole(ConsoleColor.Yellow, string.Format("[Status:] {0}", this._consoleStatus.ToString()));

                    try
                    {
                        this._windowsService.OnContinue();
                        this._consoleStatus = ServiceControllerStatus.Running;
                    }
                    catch (Exception e)
                    {
                        InternalLogger.Log(e);
                        this._consoleStatus = originalConsoleStatus;
                    }
                }

                this.WriteToConsole(ConsoleColor.Yellow, string.Format("[Status:] {0}", this._consoleStatus.ToString()));
            }
            else
            {
                if (WindowsServiceBase.ServiceExists(this._setupInfo.ServiceName))
                {
                    if (this.ServiceStatus == ServiceControllerStatus.Paused)
                    {
                        this.WriteToConsole(ConsoleColor.Yellow, string.Format("[Status:] {0}", this.ServiceStatus.ToString()));
                        WindowsServiceBase.Continue(this._setupInfo.ServiceName);
                    }

                    this.WriteToConsole(ConsoleColor.Yellow, string.Format("[Status:] {0}", this.ServiceStatus.ToString()));
                }
                else
                {
                    this.WriteToConsole(ConsoleColor.Red, "The specified service does not exist as an installed service.", true, false);
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// Method WriteServiceInfo.
 /// </summary>
 private void WriteServiceInfo()
 {
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Administrator: {0}", new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Service Name:  {0}", this._setupInfo.ServiceName).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Display Name:  {0}", this._setupInfo.DisplayName).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Mode:          {0}", this.IsConsoleMode ? "Console" : "Service").PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Status:        {0}", this.IsConsoleMode ? this._consoleStatus : this.ServiceStatus).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, string.Format("Installed:     {0}", WindowsServiceBase.ServiceExists(this._setupInfo.ServiceName)).PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "Description:".PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "    " + this._setupInfo.Description.PadRight(66), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "Assembly:".PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "    " + this._setupInfo.ServiceAssembly.FullName.PadRight(66), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "Assembly File: ".PadRight(70), true, false);
     this.WriteToConsole(ConsoleColor.Yellow, "    " + this._setupInfo.ServiceAssembly.Location.PadRight(66), true, false);
 }