Created
May 30, 2017 08:58
-
-
Save bigtan/3ea78a29a79ea4f272a44fa90bc1df39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Diagnostics; | |
using Topshelf; | |
namespace CowService | |
{ | |
public class ProxyProcess | |
{ | |
readonly Process proxy; | |
public ProxyProcess() | |
{ | |
proxy = new Process(); | |
proxy.StartInfo.FileName = "cow.exe"; | |
proxy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | |
} | |
public void Start() { proxy.Start(); } | |
public void Stop() { proxy.Kill(); } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
HostFactory.Run(x => | |
{ | |
x.Service<ProxyProcess>(s => | |
{ | |
s.ConstructUsing(name => new ProxyProcess()); | |
s.WhenStarted(tc => tc.Start()); | |
s.WhenStopped(tc => tc.Stop()); | |
}); | |
x.RunAsLocalSystem(); | |
x.StartAutomatically(); | |
x.SetDescription("Shadowsocks client cow."); | |
x.SetDisplayName("cow"); | |
x.SetServiceName("cow"); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment