mirror of https://github.com/2dust/v2rayN
Add Reboot as administrator
parent
e47caf8c4f
commit
dc16136c59
|
@ -30,14 +30,15 @@ namespace v2rayN
|
|||
{
|
||||
Global.ExePathKey = Utils.GetMD5(Utils.GetExePath());
|
||||
|
||||
var rebootas = (e.Args ?? new string[] { }).Any(t => t == Global.RebootAs);
|
||||
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, Global.ExePathKey, out bool bCreatedNew);
|
||||
if (!bCreatedNew)
|
||||
if (!rebootas && !bCreatedNew)
|
||||
{
|
||||
ProgramStarted.Set();
|
||||
Current.Shutdown();
|
||||
Environment.Exit(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Global.processJob = new Job();
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
public const string DelayUnit = "";
|
||||
public const string SpeedUnit = "";
|
||||
public const int MinFontSize = 10;
|
||||
public const string RebootAs = "rebootas";
|
||||
|
||||
public static readonly List<string> IEProxyProtocols = new() {
|
||||
"{ip}:{http_port}",
|
||||
|
|
|
@ -933,6 +933,15 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Reboot as administrator 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string menuRebootAsAdmin {
|
||||
get {
|
||||
return ResourceManager.GetString("menuRebootAsAdmin", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Reload 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1153,4 +1153,7 @@
|
|||
<data name="MsgSkipSubscriptionUpdate" xml:space="preserve">
|
||||
<value>Updates are not enabled, skip this subscription</value>
|
||||
</data>
|
||||
<data name="menuRebootAsAdmin" xml:space="preserve">
|
||||
<value>Reboot as administrator</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1153,4 +1153,7 @@
|
|||
<data name="MsgSkipSubscriptionUpdate" xml:space="preserve">
|
||||
<value>未启用更新,跳过此订阅</value>
|
||||
</data>
|
||||
<data name="menuRebootAsAdmin" xml:space="preserve">
|
||||
<value>以管理员身份重启</value>
|
||||
</data>
|
||||
</root>
|
|
@ -7,6 +7,7 @@ using Microsoft.Win32;
|
|||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reactive;
|
||||
|
@ -121,6 +122,7 @@ namespace v2rayN.ViewModels
|
|||
public ReactiveCommand<Unit, Unit> OptionSettingCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> RoutingSettingCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> GlobalHotkeySettingCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> RebootAsAdminCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> ImportOldGuiConfigCmd { get; }
|
||||
|
||||
|
@ -431,6 +433,10 @@ namespace v2rayN.ViewModels
|
|||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||
}
|
||||
});
|
||||
RebootAsAdminCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
RebootAsAdmin();
|
||||
});
|
||||
ClearServerStatisticsCmd = ReactiveCommand.Create(() =>
|
||||
{
|
||||
_statistics?.ClearAllServerStatistics();
|
||||
|
@ -1292,6 +1298,24 @@ namespace v2rayN.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
private void RebootAsAdmin()
|
||||
{
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Arguments = Global.RebootAs,
|
||||
WorkingDirectory = Utils.StartupPath(),
|
||||
FileName = Utils.GetExePath(),
|
||||
Verb = "runas",
|
||||
};
|
||||
try
|
||||
{
|
||||
Process.Start(startInfo);
|
||||
MyAppExit(false);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void ImportOldGuiConfig()
|
||||
{
|
||||
OpenFileDialog fileDialog = new()
|
||||
|
|
|
@ -118,6 +118,7 @@ namespace v2rayN.Views
|
|||
this.BindCommand(ViewModel, vm => vm.OptionSettingCmd, v => v.menuOptionSetting).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingSettingCmd, v => v.menuRoutingSetting).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.GlobalHotkeySettingCmd, v => v.menuGlobalHotkeySetting).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables);
|
||||
|
||||
|
|
Loading…
Reference in New Issue