diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs index 02c5f9751d..10f1337e46 100644 --- a/src/MaaWpfGui/Main/Bootstrapper.cs +++ b/src/MaaWpfGui/Main/Bootstrapper.cs @@ -215,14 +215,7 @@ namespace MaaWpfGui.Main } } - private static bool IsUserAdministrator() - { - WindowsIdentity identity = WindowsIdentity.GetCurrent(); - WindowsPrincipal principal = new WindowsPrincipal(identity); - SecurityIdentifier adminSid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); - - return principal.IsInRole(adminSid); - } + public static bool IsUserAdministrator() => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); /// protected override void ConfigureIoC(IStyletIoCBuilder builder) diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 200abdefb6..cc4548800a 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -270,6 +270,9 @@ You can cancel this popup by clicking the Settings - About Us - Issue Reporting Configuration <{0}> added successfully Configuration <{0}> already exists Auto start with PC + + Administrator mode does not support startup on boot. It is not recommended to run MAA with administrator privileges for an extended period.\nIf necessary, please go to Control Panel > Windows Tools > Task Scheduler to create a custom task. When setting the trigger, make sure to check「Run with highest privileges」 + Auto Run task after launched Auto Minimize after launched Client Type diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index a8b326a7b1..d061e5ee88 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -270,6 +270,9 @@ 構成< {0}>が正常に追加されました 構成 < {0}> は既に存在します スタートアップ + + 管理者権限での起動は、起動時の自動実行をサポートしていません。MAAを長時間管理者権限で実行することはお勧めしません。\n必要な場合は、「コントロールパネル > Windowsツール > タスクスケジューラ」に移動してカスタムタスクを作成してください。トリガーを設定する際に、「最も高い特権で実行」を必ず選択してください。 + アプリの起動時に自動的に実行 アプリの起動時に自動的に最小化 クライアントバージョン diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index f4338c81f1..3c19805817 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -270,6 +270,9 @@ 구성 < {0}>가 성공적으로 추가되었습니다 구성 < {0}>가 이미 있습니다 시스템 시작 시 MAA 실행 + + 관리자 권한으로 실행 시 부팅 시 자동 실행이 지원되지 않습니다. MAA를 관리자 권한으로 장시간 실행하는 것은 권장하지 않습니다.\n필요할 경우 제어판 > Windows 도구 > 작업 스케줄러에서 사용자 지정 작업을 생성하세요. 트리거를 설정할 때 "가장 높은 권한으로 실행"을 반드시 선택하십시오. + MAA 실행 후 작업 자동 시작 MAA 실행 후 최소화 클라이언트 종류 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index e752eacd35..48186d59b2 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -270,6 +270,9 @@ 配置 <{0}> 添加成功 配置 <{0}> 已存在 开机自动启动 MAA + + 管理员权限启动不支持开机自启。不建议长期以管理员权限运行 MAA。\n如确有需要,请前往 控制面板 > Windows 工具 > 任务计划程序 创建自定义任务。设置触发器时,请确保勾选「使用最高权限运行」。 + 启动 MAA 后直接运行 启动 MAA 后直接最小化 客户端类型 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index ee68f7a01b..831e75196b 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -270,6 +270,9 @@ 配置 <{0}> 新增成功 配置 <{0}> 已存在 開機自動啟動 MAA + + "以系統管理員身分執行" 不支援開機自動啟動。不建議長期以系統管理員身分執行 MAA。\n如有需要,請前往 控制台 > 系統管理工具 > 工作排程器 建立工作。設定安全性選項時,請確保已勾選「以最高權限執行」。 + 啟動 MAA 後直接執行 啟動 MAA 後直接最小化 用戶端類型 diff --git a/src/MaaWpfGui/Utilities/AutoStart.cs b/src/MaaWpfGui/Utilities/AutoStart.cs index 7d4cdb426e..42d2f3959d 100644 --- a/src/MaaWpfGui/Utilities/AutoStart.cs +++ b/src/MaaWpfGui/Utilities/AutoStart.cs @@ -15,6 +15,9 @@ using System; using System.Diagnostics; using System.IO; using System.Security; +using MaaWpfGui.Helper; +using System.Windows; +using MaaWpfGui.Main; using Microsoft.Win32; using Serilog; @@ -61,6 +64,12 @@ namespace MaaWpfGui.Utilities /// The value. public static bool CheckStart() { + if (Bootstrapper.IsUserAdministrator()) + { + SetStart(false, out _); + return false; + } + try { using var key = Registry.CurrentUser.OpenSubKey(CurrentUserRunKey, false); @@ -83,6 +92,12 @@ namespace MaaWpfGui.Utilities { error = string.Empty; + if (set && Bootstrapper.IsUserAdministrator()) + { + error = LocalizationHelper.GetString("LaunchOnSystemStartupAdminPrompt"); + return false; + } + try { using var key = Registry.CurrentUser.OpenSubKey(CurrentUserRunKey, true); diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs index 4de144ec03..4716cea323 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs @@ -24,6 +24,7 @@ using System.Threading; using System.Windows; using MaaWpfGui.Constants; using MaaWpfGui.Helper; +using MaaWpfGui.Main; using MaaWpfGui.States; using MaaWpfGui.Utilities; using MaaWpfGui.ViewModels.UI; @@ -59,8 +60,8 @@ public class StartSettingsUserControlModel : PropertyChangedBase { if (!AutoStart.SetStart(value, out var error)) { - _logger.Error("Failed to set startup."); - MessageBoxHelper.Show(error); + _logger.Error($"Failed to set startup: {error}"); + MessageBoxHelper.Show(error, LocalizationHelper.GetString("Warning"), icon: MessageBoxImage.Warning); return; }