Add Reboot as administrator

pull/3621/head
2dust 2 years ago
parent e47caf8c4f
commit dc16136c59

@ -30,14 +30,15 @@ namespace v2rayN
{ {
Global.ExePathKey = Utils.GetMD5(Utils.GetExePath()); 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); ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, Global.ExePathKey, out bool bCreatedNew);
if (!bCreatedNew) if (!rebootas && !bCreatedNew)
{ {
ProgramStarted.Set(); ProgramStarted.Set();
Current.Shutdown(); Current.Shutdown();
Environment.Exit(0); Environment.Exit(0);
return; return;
} }
Global.processJob = new Job(); Global.processJob = new Job();

@ -80,6 +80,7 @@
public const string DelayUnit = ""; public const string DelayUnit = "";
public const string SpeedUnit = ""; public const string SpeedUnit = "";
public const int MinFontSize = 10; public const int MinFontSize = 10;
public const string RebootAs = "rebootas";
public static readonly List<string> IEProxyProtocols = new() { public static readonly List<string> IEProxyProtocols = new() {
"{ip}:{http_port}", "{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> /// <summary>
/// 查找类似 Reload 的本地化字符串。 /// 查找类似 Reload 的本地化字符串。
/// </summary> /// </summary>

@ -1153,4 +1153,7 @@
<data name="MsgSkipSubscriptionUpdate" xml:space="preserve"> <data name="MsgSkipSubscriptionUpdate" xml:space="preserve">
<value>Updates are not enabled, skip this subscription</value> <value>Updates are not enabled, skip this subscription</value>
</data> </data>
<data name="menuRebootAsAdmin" xml:space="preserve">
<value>Reboot as administrator</value>
</data>
</root> </root>

@ -1153,4 +1153,7 @@
<data name="MsgSkipSubscriptionUpdate" xml:space="preserve"> <data name="MsgSkipSubscriptionUpdate" xml:space="preserve">
<value>未启用更新,跳过此订阅</value> <value>未启用更新,跳过此订阅</value>
</data> </data>
<data name="menuRebootAsAdmin" xml:space="preserve">
<value>以管理员身份重启</value>
</data>
</root> </root>

@ -7,6 +7,7 @@ using Microsoft.Win32;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat; using Splat;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Reactive; using System.Reactive;
@ -121,6 +122,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> OptionSettingCmd { get; } public ReactiveCommand<Unit, Unit> OptionSettingCmd { get; }
public ReactiveCommand<Unit, Unit> RoutingSettingCmd { get; } public ReactiveCommand<Unit, Unit> RoutingSettingCmd { get; }
public ReactiveCommand<Unit, Unit> GlobalHotkeySettingCmd { get; } public ReactiveCommand<Unit, Unit> GlobalHotkeySettingCmd { get; }
public ReactiveCommand<Unit, Unit> RebootAsAdminCmd { get; }
public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; } public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; }
public ReactiveCommand<Unit, Unit> ImportOldGuiConfigCmd { get; } public ReactiveCommand<Unit, Unit> ImportOldGuiConfigCmd { get; }
@ -431,6 +433,10 @@ namespace v2rayN.ViewModels
_noticeHandler?.Enqueue(ResUI.OperationSuccess); _noticeHandler?.Enqueue(ResUI.OperationSuccess);
} }
}); });
RebootAsAdminCmd = ReactiveCommand.Create(() =>
{
RebootAsAdmin();
});
ClearServerStatisticsCmd = ReactiveCommand.Create(() => ClearServerStatisticsCmd = ReactiveCommand.Create(() =>
{ {
_statistics?.ClearAllServerStatistics(); _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() private void ImportOldGuiConfig()
{ {
OpenFileDialog fileDialog = new() 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.OptionSettingCmd, v => v.menuOptionSetting).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RoutingSettingCmd, v => v.menuRoutingSetting).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.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.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables);

Loading…
Cancel
Save