Installer.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Configuration.Install;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace SetupLibrary
  11. {
  12. [RunInstaller(true)]
  13. public partial class Installer : System.Configuration.Install.Installer
  14. {
  15. public Installer()
  16. {
  17. InitializeComponent();
  18. }
  19. protected override void OnAfterInstall(IDictionary savedState)
  20. {
  21. // LogWrite("OnAfterInstall!");
  22. //LogWrite(path); //开机启动
  23. //RegistryKey hklm = Registry.LocalMachine;
  24. //RegistryKey run = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
  25. //try
  26. //{//64位系统在计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run
  27. // LogWrite("设置注册表!");
  28. // LogWrite(path.Substring(0, path.Length - 1) + @"BingPic\BingPic.exe");
  29. // run.CreateSubKey("Bing", true);
  30. // run.SetValue("Bing", path.Substring(0, path.Length - 1) + @"BingPic\BingPic.exe");
  31. // hklm.Close();
  32. // LogWrite("设置结束!");
  33. //}
  34. //catch (Exception my)
  35. //{
  36. // my.ToString();
  37. // LogWrite(my.ToString());
  38. //}
  39. string path = this.Context.Parameters["targetdir"];//获取用户设定的安装目标路径, 注意,需要在Setup项目里面自定义操作的属性栏里面的CustomActionData添加上/targetdir="[TARGETDIR]\"
  40. System.Diagnostics.Process p = new System.Diagnostics.Process();
  41. p.StartInfo.WorkingDirectory = path;
  42. p.StartInfo.FileName = path + "/Mir3AU.exe";
  43. p.Start();
  44. base.OnAfterInstall(savedState);
  45. }
  46. public override void Install(IDictionary stateSaver)
  47. {
  48. //LogWrite("Install!");
  49. base.Install(stateSaver);
  50. }
  51. protected override void OnBeforeInstall(IDictionary savedState)
  52. {
  53. //LogWrite("OnBeforeInstall!");
  54. base.OnBeforeInstall(savedState);
  55. }
  56. public override void Uninstall(IDictionary savedState)
  57. {
  58. //LogWrite("Uninstall!");
  59. base.Uninstall(savedState);
  60. }
  61. public override void Rollback(IDictionary savedState)
  62. {
  63. //LogWrite("Rollback");
  64. base.Rollback(savedState);
  65. }
  66. public void LogWrite(string str)
  67. {
  68. string LogPath = @"c:\log\";
  69. using (System.IO.StreamWriter sw = new System.IO.StreamWriter(LogPath + @"SetUpLog.txt", true))
  70. {
  71. sw.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + str + "\n");
  72. }
  73. }
  74. }
  75. }