ProjectInstaller.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Configuration.Install;
  6. using System.Windows.Forms;
  7. using Microsoft.Win32;
  8. namespace US.Browser.Service
  9. {
  10. [RunInstaller(true)]
  11. public partial class ProjectInstaller : System.Configuration.Install.Installer
  12. {
  13. public ProjectInstaller()
  14. {
  15. InitializeComponent();
  16. //UKJOpen();//设置开机自动启动云浏览器
  17. }
  18. /// <summary>
  19. /// 设置开机启动
  20. /// </summary>
  21. //public void UKJOpen()
  22. //{
  23. // //获取程序执行路径..
  24. // string USTP = Application.ExecutablePath;//获取文件安装的路径
  25. // RegistryKey _UZC = Registry.LocalMachine;//打开注册表
  26. // RegistryKey _UZR = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");//打开开机启动的文件夹
  27. // try
  28. // {
  29. // _UZC.SetValue("YDIE", USTP);//设置开机启动
  30. // _UZC.Close();//关闭注册表
  31. // }
  32. // catch (Exception e)
  33. // {
  34. // MessageBox.Show("无法设置开机启动");
  35. // }
  36. //}
  37. //安装之后
  38. protected override void OnAfterInstall(IDictionary savedState)
  39. {
  40. System.Diagnostics.Process p = new System.Diagnostics.Process();
  41. p.StartInfo.FileName = "cmd.exe";
  42. p.StartInfo.UseShellExecute = false;
  43. p.StartInfo.RedirectStandardInput = true;
  44. p.StartInfo.RedirectStandardOutput = true;
  45. p.StartInfo.RedirectStandardError = true;
  46. p.StartInfo.CreateNoWindow = true;
  47. p.Start();
  48. p.StandardInput.WriteLine("sc stop USservice");
  49. p.StandardInput.WriteLine("sc config USservice type= interact type= own");
  50. p.StandardInput.WriteLine("sc start USservice");
  51. //p.WaitForExit(10);
  52. //p.StandardInput.WriteLine("exit");
  53. p.Close();
  54. }
  55. //卸载之前
  56. protected override void OnBeforeUninstall(IDictionary savedState)
  57. {
  58. System.Diagnostics.Process p = new System.Diagnostics.Process();
  59. p.StartInfo.FileName = "cmd.exe";
  60. p.StartInfo.UseShellExecute = false;
  61. p.StartInfo.RedirectStandardInput = true;
  62. p.StartInfo.RedirectStandardOutput = true;
  63. p.StartInfo.RedirectStandardError = true;
  64. p.StartInfo.CreateNoWindow = true;
  65. p.Start();
  66. p.StandardInput.WriteLine("sc stop USservice");
  67. p.StandardInput.WriteLine("exit");
  68. p.Close();
  69. }
  70. }
  71. }