LJInstallHelper.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.IO;
  2. using Microsoft.Win32;
  3. using LJLib.Cmd;
  4. using System.ServiceProcess;
  5. namespace LJLib.InstallHelper
  6. {
  7. public static class LJInstallHelper
  8. {
  9. public static string Install(string ServerName, string DisplayName, string Description, string ImagePath)
  10. {
  11. LJInstallGlobal.ServerName = ServerName;
  12. LJInstallGlobal.DisplayName = DisplayName;
  13. LJInstallGlobal.Description = Description;
  14. LJInstallGlobal.ImagePath = ImagePath;
  15. string cmd = "\"" + InstallUtilPath + "\" \"" + LJInstallGlobal.CurrentPath + "\\" + LJInstallGlobal.FileName + "\"";
  16. return CMDHelper.RunWithReturn(cmd);
  17. }
  18. public static string Uninstall(string ServerName)
  19. {
  20. LJInstallGlobal.ServerName = ServerName;
  21. string cmd = "\"" + InstallUtilPath + "\" /u \"" + LJInstallGlobal.CurrentPath + "\\" + LJInstallGlobal.FileName + "\"";
  22. return CMDHelper.RunWithReturn(cmd);
  23. }
  24. public static bool Exitst(string ServerName)
  25. {
  26. try
  27. {
  28. ServiceController sc = new ServiceController(ServerName);
  29. var status = sc.Status;
  30. return true;
  31. }
  32. catch (System.Exception ex)
  33. {
  34. return false;
  35. }
  36. }
  37. private static string frameworkpath
  38. {
  39. get
  40. {
  41. var netkey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey(".NETFramework");
  42. return netkey.GetValue("InstallRoot").ToString();
  43. }
  44. }
  45. private static string InstallUtilPath
  46. {
  47. get
  48. {
  49. string fwp = frameworkpath;
  50. if (!fwp.EndsWith("\\"))
  51. {
  52. fwp += "\\";
  53. }
  54. if (Directory.Exists(fwp + "v4.0.30319"))
  55. {
  56. return fwp + "v4.0.30319\\InstallUtil.exe";
  57. }
  58. if (Directory.Exists(fwp + "v2.0.50727"))
  59. {
  60. return fwp + "v2.0.50727\\InstallUtil.exe";
  61. }
  62. if (Directory.Exists(fwp + "v1.1.4322"))
  63. {
  64. return fwp + "v1.1.4322\\InstallUtil.exe";
  65. }
  66. return string.Empty;
  67. }
  68. }
  69. }
  70. }