mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-23 11:26:54 +00:00
启动退出时执行自定义命令
This commit is contained in:
parent
47dce69aa4
commit
b4ae31fc83
2 changed files with 38 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue