program.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. namespace EfemDual_Setup
  7. {
  8. static class Program
  9. {
  10. /// <summary>
  11. /// The main entry point for the application.
  12. /// </summary>
  13. [STAThread]
  14. static void Main()
  15. {
  16. Application.EnableVisualStyles();
  17. Application.SetCompatibleTextRenderingDefault(false);
  18. Application.Run(new EfemDualSetup());
  19. }
  20. }
  21. public partial class EfemDualSetup : ApplicationContext
  22. {
  23. public EfemDualSetup()
  24. {
  25. var exeFilePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  26. exeFilePath = exeFilePath.Substring(0, exeFilePath.LastIndexOf("\\")) + "\\" + "EfemDualSetupPackages.exe";
  27. System.IO.FileInfo fi = new System.IO.FileInfo(exeFilePath);
  28. if (fi.Exists)
  29. {
  30. }
  31. else
  32. {
  33. if (MessageBox.Show(string.Format("当前安装包不包含EfemDual配置的安装信息,安装失败!"), "EfemDual安装", MessageBoxButtons.OK,
  34. MessageBoxIcon.Error) == DialogResult.OK)
  35. {
  36. Environment.Exit(0);
  37. }
  38. }
  39. System.Collections.ArrayList procList = new System.Collections.ArrayList();
  40. foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
  41. {
  42. procList.Add(thisProc.ProcessName);
  43. }
  44. if (procList.Contains("EfemDualRT") || procList.Contains("EfemDualUI"))
  45. {
  46. //if (MessageBox.Show(string.Format("检测程序尚在运行,是否使其终止运行!"), "EfemDual安装", MessageBoxButtons.OKCancel,
  47. // MessageBoxIcon.Error) == DialogResult.OK)
  48. //{
  49. // CloseProc("EfemDualRT");
  50. // CloseProc("EfemDualUI");
  51. // System.Diagnostics.Process.Start(exeFilePath);
  52. //}
  53. if (MessageBox.Show(string.Format("检测程序尚在运行,安装失败!"), "EfemDual安装", MessageBoxButtons.OK,
  54. MessageBoxIcon.Error) == DialogResult.OK)
  55. {
  56. }
  57. }
  58. else
  59. {
  60. //if (MessageBox.Show(string.Format("即将运行EfemDual安装程序,请确认以下信息是否正确:\n\n程序变更号:{0}\n\n请确认是否继续完成安装?", tmVariation), "EfemDual安装", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  61. System.Diagnostics.Process.Start(exeFilePath);
  62. }
  63. Environment.Exit(0);
  64. }
  65. private bool CloseProc(string procName)
  66. {
  67. bool result = false;
  68. foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
  69. {
  70. if (thisProc.ProcessName == procName)
  71. {
  72. // if (!thisProc.CloseMainWindow())
  73. thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程
  74. result = true;
  75. }
  76. }
  77. return result;
  78. }
  79. }
  80. }