Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace uTorrentBlockXunlei
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string sIPFilterFilename = "ipfilter.dat";
- string sNodePath = null;
- Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
- try
- {
- // 找出正在執行中的 node.exe
- Process[] pa = Process.GetProcessesByName("node");
- // 有的話就先強制關閉
- if (pa.Length > 0)
- {
- sNodePath = pa[0].MainModule.FileName;
- foreach (Process p in pa)
- {
- if (!p.HasExited)
- p.Kill();
- p.WaitForExit();
- }
- }
- // 沒有的話,就檢查指定路徑下有沒有 node.exe
- else
- {
- sNodePath = "nodejs\\node.exe";
- if (!File.Exists(sNodePath))
- return;
- }
- // 找出執行中的 uTorrent.exe
- pa = Process.GetProcessesByName("utorrent");
- // 有的話
- if (pa.Length > 0)
- {
- // 還原乾淨的 ipfilter.dat
- if (File.Exists(sIPFilterFilename))
- File.Copy(sIPFilterFilename, Path.GetDirectoryName(pa[0].MainModule.FileName) + "\\" + sIPFilterFilename, true);
- // 重啟 node.exe
- Process.Start(sNodePath, "utorrent.js");
- Environment.Exit(0);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement