diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 90977fd0..f1993515 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -49,7 +49,8 @@ namespace v2rayN.Forms ConfigHandler.LoadConfig(ref config); v2rayHandler = new V2rayHandler(); v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; - + string command = config.Event.open; + ExecCmd(command); if (config.enableStatistics) { statistics = new StatisticsHandler(config, UpdateStatisticsHandler); @@ -85,9 +86,11 @@ namespace v2rayN.Forms { if (e.CloseReason == CloseReason.UserClosing) { + string command = config.Event.close; StorageUI(); e.Cancel = true; HideForm(); + ExecCmd(command); return; } } @@ -151,6 +154,23 @@ namespace v2rayN.Forms } } + private void ExecCmd(string cmd) + { + if (!cmd.Equals("")) + { + Process p = new Process(); + p.StartInfo.FileName = "cmd.exe"; + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardInput = true; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.RedirectStandardError = true; + p.StartInfo.CreateNoWindow = true; + p.Start(); + p.StandardInput.WriteLine(cmd + "&exit"); + p.Close(); + } + } + #endregion #region 显示服务器 listview 和 menu diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index fb737942..30115a66 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -206,6 +206,10 @@ namespace v2rayN.Mode { get; set; } + public Event Event + { + get; set; + } #region 函数 @@ -737,4 +741,17 @@ namespace v2rayN.Mode get; set; } } + [Serializable] + public class Event + { + public string open + { + get; set; + } + + public string close + { + get; set; + } + } }