LJInstaller.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.ComponentModel;
  2. using System.Configuration.Install;
  3. using System.ServiceProcess;
  4. using Microsoft.Win32;
  5. namespace LJLib.InstallHelper
  6. {
  7. [RunInstaller(true)]
  8. public partial class LJInstaller : System.Configuration.Install.Installer
  9. {
  10. public LJInstaller()
  11. {
  12. InitializeComponent();
  13. // DONE: 读取服务
  14. this.serviceInstaller1.ServiceName = LJInstallGlobal.ServerName;
  15. this.serviceInstaller1.DisplayName = LJInstallGlobal.DisplayName;
  16. this.serviceInstaller1.Description = LJInstallGlobal.Description;
  17. }
  18. private void LJInstaller_AfterInstall(object sender, InstallEventArgs e)
  19. {
  20. var curPath = LJInstallGlobal.ImagePath;
  21. if (!string.IsNullOrEmpty(curPath))
  22. {
  23. // DONE: 修改命令行
  24. RegistryKey service = Registry.LocalMachine.OpenSubKey("SYSTEM").OpenSubKey("CurrentControlSet").OpenSubKey("services").OpenSubKey(LJInstallGlobal.ServerName, true);
  25. service.SetValue("ImagePath", curPath);
  26. }
  27. ServiceController sc = new ServiceController(LJInstallGlobal.ServerName);
  28. if (sc.Status != ServiceControllerStatus.Running)
  29. {
  30. sc.Start();
  31. }
  32. }
  33. private void LJInstaller_BeforeUninstall(object sender, InstallEventArgs e)
  34. {
  35. // DONE: 停止服务
  36. ServiceController sc = new ServiceController(LJInstallGlobal.ServerName);
  37. if (sc.Status != ServiceControllerStatus.Stopped)
  38. {
  39. sc.Stop();
  40. }
  41. }
  42. }
  43. }