Skip to content

Support Always Run As Administrator #3573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 116 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
7549bba
Add administrator mode check
Jack251970 May 22, 2025
369ed86
Add administrator text in tray icon
Jack251970 May 22, 2025
10d379f
Support running application under non-admin mode & Show UAC dialogs w…
Jack251970 May 22, 2025
484f91c
Improve UAC dialog
Jack251970 May 22, 2025
7611b00
Add new restart api
Jack251970 May 22, 2025
d29a5d4
Add setting model
Jack251970 May 22, 2025
40cf413
Add admin support for auto startup
Jack251970 May 22, 2025
fe70a72
Add admin mode configuration in general page
Jack251970 May 22, 2025
0edd626
Remove useless semicolon
Jack251970 May 22, 2025
91f7a4f
Remove useless semicolon
Jack251970 May 22, 2025
902c8f4
Check value changed
Jack251970 May 22, 2025
c5c24ac
Check run level
Jack251970 May 22, 2025
1073061
Remove old before creating new one
Jack251970 May 22, 2025
e9c40e4
Revert "Add new restart api"
Jack251970 May 23, 2025
365ba6a
Code quality
Jack251970 May 23, 2025
eae4a95
Use readonly bool variable
Jack251970 May 23, 2025
52c36ff
Only restart from non-admin to admin & Fix restart as administrator i…
Jack251970 May 23, 2025
35f4fd5
Fix restart as administrator issue
Jack251970 May 23, 2025
eacccf9
Add code comments & Use local function
Jack251970 May 23, 2025
d6462f4
Move restart function to app class
Jack251970 May 23, 2025
479b49d
Throw UnauthorizedAccessException when encountering admin issue
Jack251970 May 23, 2025
c3ec002
Show message box to ask users to restart as administrator when encoun…
Jack251970 May 23, 2025
80c0288
Throw exception when editing highest run level task
Jack251970 May 23, 2025
1b80290
Do not show noticification when run level is correct
Jack251970 May 23, 2025
ca6f077
Merge branch 'dev' into administrator_mode
Jack251970 Jun 3, 2025
ba1ada7
Continue to restart app as administrator if app is run as administrat…
Jack251970 Jun 3, 2025
b2edea4
Improve code quality
Jack251970 Jun 3, 2025
de26abe
Use api functions instead
Jack251970 Jun 3, 2025
23f2489
Force admin restart and fix build issue
Jack251970 Jun 3, 2025
2c1f161
Merge branch 'dev' into administrator_mode
Jack251970 Jun 10, 2025
1a8334f
Add RunAsDesktopUser helper method
Jack251970 Jun 11, 2025
e391c98
Code quality
Jack251970 Jun 11, 2025
100c21a
Add new api to run process as desktop user
Jack251970 Jun 11, 2025
fc53efd
Use new api function to open application
Jack251970 Jun 11, 2025
d77993e
Use new api function to start shell process
Jack251970 Jun 11, 2025
4cf6636
Fix handle close issue
Jack251970 Jun 11, 2025
f1f7309
Add working directory check & Add try-catch
Jack251970 Jun 11, 2025
e8c03c6
Update documents
Jack251970 Jun 11, 2025
ea9ede2
Fix deelevate process running issue
Jack251970 Jun 11, 2025
d13901b
Update work directory correctly
Jack251970 Jun 11, 2025
f9b2be1
Let work directory can be empty
Jack251970 Jun 11, 2025
30deb6d
Fix argument sequence issue
Jack251970 Jun 11, 2025
fb4735f
Fix program deelevate open issue
Jack251970 Jun 11, 2025
b15cece
Fix absolute exe file path issue
Jack251970 Jun 11, 2025
255ca5a
Improve code quality
Jack251970 Jun 11, 2025
433e0fd
Improve uac dialog path
Jack251970 Jun 12, 2025
21e8d92
Add show uac dialog api function
Jack251970 Jun 12, 2025
0d1358f
Add return value for start process api function
Jack251970 Jun 12, 2025
a775323
Improve uac dialog api function
Jack251970 Jun 12, 2025
a3212af
Dynamically find wt.exe
Jack251970 Jun 12, 2025
8b8fcd8
Add IsAdmin
Jack251970 Jun 12, 2025
94f0bb9
Handle command running with administrator mode correctly
Jack251970 Jun 12, 2025
6842fca
Replace IntPtr.Zero with Handle or HWND
Jack251970 Jun 12, 2025
9c6c015
Reflect user intent
Jack251970 Jun 12, 2025
8cfaeea
Return value of RunAsDesktopUser
Jack251970 Jun 12, 2025
61717dc
Ensure SetImageAsync exceptions are handled
Jack251970 Jun 12, 2025
393d106
Fix command line pass issue
Jack251970 Jun 13, 2025
2df7a61
Add command project
Jack251970 Jun 13, 2025
13b5012
Add command executer path
Jack251970 Jun 13, 2025
b8a697c
Fix running issue
Jack251970 Jun 13, 2025
a0ebe29
Improve api function
Jack251970 Jun 13, 2025
3ed8af8
Use new api for program plugin
Jack251970 Jun 13, 2025
5551bdf
Remove uac dialog api function
Jack251970 Jun 13, 2025
2c0210c
Revert unnecessary changes in solution file
Jack251970 Jun 13, 2025
898dbb8
Use new api for uwp package opening
Jack251970 Jun 13, 2025
4ebfb3c
Add api function
Jack251970 Jun 13, 2025
a2be6e0
Use new api for shell plugin
Jack251970 Jun 13, 2025
50a8e88
Use double quotes to fix possible issue
Jack251970 Jun 13, 2025
d56f0a0
Improve process information handler
Jack251970 Jun 13, 2025
dae6f5d
Use WinExe to avoid console ui
Jack251970 Jun 13, 2025
6109504
Add solution assembly information
Jack251970 Jun 13, 2025
8287b33
Fix typo
Jack251970 Jun 13, 2025
be2c59e
Call Win32Helper.IsAdministrator() directly
Jack251970 Jun 13, 2025
d1b4c3c
Merge branch 'administrator_mode' of https://github.com/Flow-Launcher…
Jack251970 Jun 13, 2025
5ddf705
Fix typo
Jack251970 Jun 13, 2025
6843fe0
Fix parameter issue
Jack251970 Jun 13, 2025
680419f
Code quality
Jack251970 Jun 13, 2025
02de9d6
Merge branch 'dev' into administrator_mode
Jack251970 Jun 13, 2025
dd0899f
Check always running as administrator
Jack251970 Jun 13, 2025
1fabe8d
Improve string resource
Jack251970 Jun 13, 2025
def02b3
Improve xml documents
Jack251970 Jun 13, 2025
9d480fc
Quote the executable path to survive spaces & Improve code quality
Jack251970 Jun 13, 2025
f2d3ba7
Combine restart functions to one function
Jack251970 Jun 13, 2025
3a92102
Add new api RestartAppAsAdmin
Jack251970 Jun 13, 2025
d363cad
Improve code quality
Jack251970 Jun 13, 2025
0602143
Change target framework
Jack251970 Jun 13, 2025
7930d57
Add publish file
Jack251970 Jun 13, 2025
8dd9b9c
Publish command project
Jack251970 Jun 13, 2025
11c0eb3
Fix command project publish issue
Jack251970 Jun 13, 2025
7fd3a4a
Merge branch 'dev' into administrator_mode
Jack251970 Jun 13, 2025
a34e404
Change target framework
Jack251970 Jun 14, 2025
ad6d598
Change publish sequence
Jack251970 Jun 14, 2025
764b524
Use exe console type & Add flag support for helper method
Jack251970 Jun 14, 2025
2f3b973
Do not publish command project
Jack251970 Jun 14, 2025
935101c
Change command project output path
Jack251970 Jun 14, 2025
8c81808
Change default value
Jack251970 Jun 14, 2025
e1242ee
Check Process.Start usage
Jack251970 Jun 14, 2025
a76ade8
Merge branch 'dev' into administrator_mode
Jack251970 Jun 14, 2025
e5316a0
Check Process.Start usage
Jack251970 Jun 14, 2025
b6b45d4
Improve code quality
Jack251970 Jun 14, 2025
4df7264
Improve documents
Jack251970 Jun 14, 2025
1dfec7f
Merge branch 'dev' into administrator_mode
Jack251970 Jun 14, 2025
39de484
Merge branch 'administrator_mode' of https://github.com/Flow-Launcher…
Jack251970 Jun 14, 2025
44b25b4
Prefer injected Context over static Main.Context
Jack251970 Jun 15, 2025
d1daf51
Merge branch 'dev' into administrator_mode
Jack251970 Jun 15, 2025
478ba29
Change target framework to remove dll files
Jack251970 Jun 15, 2025
9119998
Build command project after main project
Jack251970 Jun 15, 2025
3493446
Support createNoWindow for start process api
Jack251970 Jun 15, 2025
7ea76b8
Support administrator handling for ShellRun api function
Jack251970 Jun 15, 2025
721bb98
Handle create no window parameter in command exe
Jack251970 Jun 15, 2025
81667d0
Fix ui issue
Jack251970 Jun 15, 2025
10567fd
Merge branch 'dev' into administrator_mode
Jack251970 Jun 16, 2025
4862a2d
Check if the application is running as administrator ealier
Jack251970 Jun 16, 2025
4416efe
Revert "Check if the application is running as administrator ealier"
Jack251970 Jun 16, 2025
71af5ef
Check if the application is running as administrator ealier
Jack251970 Jun 16, 2025
48ed897
Merge branch 'dev' into administrator_mode
Jack251970 Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ public bool HideNotifyIcon
public bool LeaveCmdOpen { get; set; }
public bool HideWhenDeactivated { get; set; } = true;

public bool AlwaysRunAsAdministrator { get; set; } = false;

public bool SearchQueryResultsWithDelay { get; set; }
public int SearchDelayTime { get; set; } = 150;

Expand Down
12 changes: 12 additions & 0 deletions Flow.Launcher.Infrastructure/Win32Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -38,7 +39,7 @@
{
var cloaked = cloak ? 1 : 0;

return PInvoke.DwmSetWindowAttribute(

Check warning on line 42 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
GetWindowHandle(window),
DWMWINDOWATTRIBUTE.DWMWA_CLOAK,
&cloaked,
Expand All @@ -50,12 +51,12 @@
var backdropType = backdrop switch
{
BackdropTypes.Acrylic => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_TRANSIENTWINDOW,
BackdropTypes.Mica => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_MAINWINDOW,

Check warning on line 54 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 54 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
BackdropTypes.MicaAlt => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_TABBEDWINDOW,

Check warning on line 55 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 55 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
_ => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_AUTO

Check warning on line 56 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`SYSTEMBACKDROP` is not a recognized word. (unrecognized-spelling)

Check warning on line 56 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`DWMSBT` is not a recognized word. (unrecognized-spelling)
};

return PInvoke.DwmSetWindowAttribute(

Check warning on line 59 in Flow.Launcher.Infrastructure/Win32Helper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
GetWindowHandle(window),
DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE,
&backdropType,
Expand Down Expand Up @@ -753,5 +754,16 @@
}

#endregion

#region Administrator Mode

public static bool IsAdministrator()
{
using var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

#endregion
}
}
6 changes: 6 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public interface IPublicAPI
/// </summary>
void RestartApp();

/// <summary>
/// Restart Flow Launcher with arguments
/// </summary>
/// <param name="arguments">Application start arguments</param>
void RestartApp(string arguments);

/// <summary>
/// Run a shell command
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void AutoStartup()
{
try
{
Helper.AutoStartup.CheckIsEnabled(_settings.UseLogonTaskForStartup);
Helper.AutoStartup.CheckIsEnabled(_settings.UseLogonTaskForStartup, _settings.AlwaysRunAsAdministrator);
}
catch (Exception e)
{
Expand Down
35 changes: 15 additions & 20 deletions Flow.Launcher/Helper/AutoStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class AutoStartup
private const string LogonTaskName = $"{Constant.FlowLauncher} Startup";
private const string LogonTaskDesc = $"{Constant.FlowLauncher} Auto Startup";

public static void CheckIsEnabled(bool useLogonTaskForStartup)
public static void CheckIsEnabled(bool useLogonTaskForStartup, bool alwaysRunAsAdministrator)
{
// We need to check both because if both of them are enabled,
// Hide Flow Launcher on startup will not work since the later one will trigger main window show event
var logonTaskEnabled = CheckLogonTask();
var logonTaskEnabled = CheckLogonTask(alwaysRunAsAdministrator);
var registryEnabled = CheckRegistry();
if (useLogonTaskForStartup)
{
// Enable logon task
if (!logonTaskEnabled)
{
Enable(true);
Enable(true, alwaysRunAsAdministrator);
}
// Disable registry
if (registryEnabled)
Expand All @@ -41,7 +41,7 @@ public static void CheckIsEnabled(bool useLogonTaskForStartup)
// Enable registry
if (!registryEnabled)
{
Enable(false);
Enable(false, alwaysRunAsAdministrator);
}
// Disable logon task
if (logonTaskEnabled)
Expand All @@ -51,7 +51,7 @@ public static void CheckIsEnabled(bool useLogonTaskForStartup)
}
}

private static bool CheckLogonTask()
private static bool CheckLogonTask(bool alwaysRunAsAdministrator)
{
using var taskService = new TaskService();
var task = taskService.RootFolder.AllTasks.FirstOrDefault(t => t.Name == LogonTaskName);
Expand All @@ -67,7 +67,7 @@ private static bool CheckLogonTask()
if (!action.Equals(Constant.ExecutablePath, StringComparison.OrdinalIgnoreCase))
{
UnscheduleLogonTask();
ScheduleLogonTask();
ScheduleLogonTask(alwaysRunAsAdministrator);
}
}

Expand Down Expand Up @@ -117,16 +117,17 @@ public static void DisableViaLogonTaskAndRegistry()
Disable(false);
}

public static void ChangeToViaLogonTask()
public static void ChangeToViaLogonTask(bool alwaysRunAsAdministrator)
{
Disable(false);
Enable(true);
Enable(true, alwaysRunAsAdministrator);
}

public static void ChangeToViaRegistry()
{
Disable(true);
Enable(false);
// We do not need to use alwaysRunAsAdministrator for registry, so we just set false here
Enable(false, false);
}

private static void Disable(bool logonTask)
Expand All @@ -149,13 +150,13 @@ private static void Disable(bool logonTask)
}
}

private static void Enable(bool logonTask)
private static void Enable(bool logonTask, bool alwaysRunAsAdministrator)
{
try
{
if (logonTask)
{
ScheduleLogonTask();
ScheduleLogonTask(alwaysRunAsAdministrator);
}
else
{
Expand All @@ -169,14 +170,15 @@ private static void Enable(bool logonTask)
}
}

private static bool ScheduleLogonTask()
private static bool ScheduleLogonTask(bool alwaysRunAsAdministrator)
{
using var td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = LogonTaskDesc;
td.Triggers.Add(new LogonTrigger { UserId = WindowsIdentity.GetCurrent().Name, Delay = TimeSpan.FromSeconds(2) });
td.Actions.Add(Constant.ExecutablePath);

if (IsCurrentUserIsAdmin())
// Only if the app is running as administrator, we can set the run level to highest
if (Win32Helper.IsAdministrator() && alwaysRunAsAdministrator)
{
td.Principal.RunLevel = TaskRunLevel.Highest;
}
Expand Down Expand Up @@ -212,13 +214,6 @@ private static bool UnscheduleLogonTask()
}
}

private static bool IsCurrentUserIsAdmin()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

private static bool UnscheduleRegistry()
{
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="PositionReset">Position Reset</system:String>
<system:String x:Key="PositionResetToolTip">Reset search window position</system:String>
<system:String x:Key="queryTextBoxPlaceholder">Type here to search</system:String>
<system:String x:Key="admin">(Admin)</system:String>

<!-- Setting General -->
<system:String x:Key="flowlauncher_settings">Settings</system:String>
Expand Down Expand Up @@ -131,6 +132,10 @@
<system:String x:Key="historyResultsForHomePage">Show History Results in Home Page</system:String>
<system:String x:Key="historyResultsCountForHomePage">Maximum History Results Shown in Home Page</system:String>
<system:String x:Key="homeToggleBoxToolTip">This can only be edited if plugin supports Home feature and Home Page is enabled.</system:String>
<system:String x:Key="alwaysRunAsAdministrator">Always run as administrator</system:String>
<system:String x:Key="alwaysRunAsAdministratorToolTip">Run Flow Launcher as administrator on system startup</system:String>
<system:String x:Key="runAsAdministratorChange">Administrator Mode Change</system:String>
<system:String x:Key="runAsAdministratorChangeAndRestart">Do you want to restart to apply administrator mode change?</system:String>

<!-- Setting Plugin -->
<system:String x:Key="searchplugin">Search Plugin</system:String>
Expand Down
6 changes: 5 additions & 1 deletion Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,13 @@ private void SoundPlay()

private void InitializeNotifyIcon()
{
var text = Win32Helper.IsAdministrator() ?
Constant.FlowLauncherFullName + " " + App.API.GetTranslation("admin") :
Constant.FlowLauncherFullName;

_notifyIcon = new NotifyIcon
{
Text = Constant.FlowLauncherFullName,
Text = text,
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
Visible = !_settings.HideNotifyIcon
};
Expand Down
7 changes: 4 additions & 3 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
Expand Down Expand Up @@ -73,8 +72,10 @@ public void ChangeQuery(string query, bool requery = false)
_mainVM.ChangeQueryText(query, requery);
}

public void RestartApp() => RestartApp(null);

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
public async void RestartApp()
public async void RestartApp(string arguments)
{
_mainVM.Hide();

Expand All @@ -89,7 +90,7 @@ public async void RestartApp()
// Restart requires Squirrel's Update.exe to be present in the parent folder,
// it is only published from the project's release pipeline. When debugging without it,
// the project may not restart or just terminates. This is expected.
UpdateManager.RestartApp(Constant.ApplicationFileName);
UpdateManager.RestartApp(Constant.ApplicationFileName, arguments);
}

public void ShowMainWindow() => _mainVM.Show();
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void ChangeAutoStartup(bool value)
{
if (Settings.UseLogonTaskForStartup)
{
AutoStartup.ChangeToViaLogonTask();
AutoStartup.ChangeToViaLogonTask(Settings.AlwaysRunAsAdministrator);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core;
Expand All @@ -22,6 +23,8 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
private readonly Portable _portable;
private readonly Internationalization _translater;

private static readonly bool _isAdministrator = Win32Helper.IsAdministrator();

public SettingsPaneGeneralViewModel(Settings settings, Updater updater, Portable portable, Internationalization translater)
{
Settings = settings;
Expand All @@ -41,6 +44,8 @@ public bool StartFlowLauncherOnSystemStartup
get => Settings.StartFlowLauncherOnSystemStartup;
set
{
if (Settings.StartFlowLauncherOnSystemStartup == value) return;

Settings.StartFlowLauncherOnSystemStartup = value;

try
Expand All @@ -49,7 +54,7 @@ public bool StartFlowLauncherOnSystemStartup
{
if (UseLogonTaskForStartup)
{
AutoStartup.ChangeToViaLogonTask();
AutoStartup.ChangeToViaLogonTask(AlwaysRunAsAdministrator);
}
else
{
Expand All @@ -65,6 +70,13 @@ public bool StartFlowLauncherOnSystemStartup
{
App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message);
}

// If we have enabled logon task startup, we need to check if we need to restart the app
// even if we encounter an error while setting the startup method
if (value && UseLogonTaskForStartup)
{
CheckAdminChangeAndAskForRestart();
}
}
}

Expand All @@ -73,6 +85,8 @@ public bool UseLogonTaskForStartup
get => Settings.UseLogonTaskForStartup;
set
{
if (UseLogonTaskForStartup == value) return;

Settings.UseLogonTaskForStartup = value;

if (StartFlowLauncherOnSystemStartup)
Expand All @@ -81,7 +95,7 @@ public bool UseLogonTaskForStartup
{
if (value)
{
AutoStartup.ChangeToViaLogonTask();
AutoStartup.ChangeToViaLogonTask(AlwaysRunAsAdministrator);
}
else
{
Expand All @@ -92,10 +106,59 @@ public bool UseLogonTaskForStartup
{
App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message);
}
}
}

// If we have enabled logon task startup, we need to check if we need to restart the app
// even if we encounter an error while setting the startup method
if (StartFlowLauncherOnSystemStartup && value)
{
CheckAdminChangeAndAskForRestart();
}
}
}

public bool AlwaysRunAsAdministrator
{
get => Settings.AlwaysRunAsAdministrator;
set
{
if (AlwaysRunAsAdministrator == value) return;

Settings.AlwaysRunAsAdministrator = value;

if (StartFlowLauncherOnSystemStartup && UseLogonTaskForStartup)
{
try
{
AutoStartup.ChangeToViaLogonTask(value);
}
catch (Exception e)
{
App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message);
}

// If we have enabled logon task startup, we need to check if we need to restart the app
// even if we encounter an error while setting the startup method
CheckAdminChangeAndAskForRestart();
}
}
}

private void CheckAdminChangeAndAskForRestart()
{
if ((AlwaysRunAsAdministrator && !_isAdministrator) || // Change from non-admin to admin
(!AlwaysRunAsAdministrator && _isAdministrator)) // Change from admin to non-admin
{
if (App.API.ShowMsgBox(
App.API.GetTranslation("runAsAdministratorChangeAndRestart"),
App.API.GetTranslation("runAsAdministratorChange"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
App.API.RestartApp(AlwaysRunAsAdministrator ? "runas" : string.Empty);
}
}
}

public List<SearchWindowScreenData> SearchWindowScreens { get; } =
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen");

Expand Down
Loading
Loading