Advertisement
Guest User

uTorrentBlockXunlei

a guest
Jul 13th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace uTorrentBlockXunlei
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             const string sIPFilterFilename = "ipfilter.dat";
  16.             string sNodePath = null;
  17.  
  18.             Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
  19.  
  20.             try
  21.             {
  22.                 // 找出正在執行中的 node.exe
  23.                 Process[] pa = Process.GetProcessesByName("node");
  24.  
  25.                 // 有的話就先強制關閉
  26.                 if (pa.Length > 0)
  27.                 {
  28.                     sNodePath = pa[0].MainModule.FileName;
  29.                     foreach (Process p in pa)
  30.                     {
  31.                         if (!p.HasExited)
  32.                             p.Kill();
  33.                         p.WaitForExit();
  34.                     }
  35.                 }
  36.                 // 沒有的話,就檢查指定路徑下有沒有 node.exe
  37.                 else
  38.                 {
  39.                     sNodePath = "nodejs\\node.exe";
  40.                     if (!File.Exists(sNodePath))
  41.                         return;
  42.                 }
  43.  
  44.                 // 找出執行中的 uTorrent.exe
  45.                 pa = Process.GetProcessesByName("utorrent");
  46.  
  47.                 // 有的話
  48.                 if (pa.Length > 0)
  49.                 {
  50.                     // 還原乾淨的 ipfilter.dat
  51.                     if (File.Exists(sIPFilterFilename))
  52.                         File.Copy(sIPFilterFilename, Path.GetDirectoryName(pa[0].MainModule.FileName) + "\\" + sIPFilterFilename, true);
  53.  
  54.                     // 重啟 node.exe
  55.                     Process.Start(sNodePath, "utorrent.js");
  56.                     Environment.Exit(0);
  57.                 }
  58.             }
  59.             catch (Exception e)
  60.             {
  61.                 Console.WriteLine(e.Message);
  62.                 Console.ReadLine();
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement