Service.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.ServiceProcess;
  7. namespace ZeroTierOneService
  8. {
  9. public partial class Service : ServiceBase
  10. {
  11. public Service()
  12. {
  13. InitializeComponent();
  14. this.ztHome = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + Path.DirectorySeparatorChar + "ZeroTier" + Path.DirectorySeparatorChar + "One";
  15. this.ztUpdatesFolder = this.ztHome + Path.DirectorySeparatorChar + "updates.d";
  16. this.ztBinary = this.ztHome + Path.DirectorySeparatorChar + (Environment.Is64BitOperatingSystem ? "zerotier-one_x64.exe" : "zerotier-one_x86.exe");
  17. this.ztService = null;
  18. }
  19. protected override void OnStart(string[] args)
  20. {
  21. startZeroTierService();
  22. }
  23. protected override void OnStop()
  24. {
  25. stopZeroTierService();
  26. }
  27. private void startZeroTierService()
  28. {
  29. }
  30. private void stopZeroTierService()
  31. {
  32. if (ztService != null)
  33. {
  34. ztService.Kill();
  35. ztService = null;
  36. }
  37. }
  38. private void ztService_Exited(object sender, System.EventArgs e)
  39. {
  40. ztService = null;
  41. }
  42. private string ztHome;
  43. private string ztUpdatesFolder;
  44. private string ztBinary;
  45. private Process ztService;
  46. }
  47. }