Add run as administrator option

This commit is contained in:
Ray Berezowski
2026-08-26 22:10:55 -04:00
parent 6d9bbbab02
commit c93f83c20d
9 changed files with 84 additions and 4 deletions

View File

@@ -134,6 +134,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Hotkey" VerticalAlignment="Center" Margin="0,0,8,8"/>
@@ -212,8 +213,15 @@
<ComboBox x:Name="ItemDisplayModeBox" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2"
Margin="0,0,0,8" SelectionChanged="ItemDisplayModeBox_SelectionChanged"/>
<TextBlock Text="Preview" Grid.Row="6" VerticalAlignment="Top" Margin="0,4,8,0"/>
<Border Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2"
<TextBlock Text="Launch Options" Grid.Row="6" VerticalAlignment="Center" Margin="0,0,8,8"/>
<CheckBox x:Name="RunAsAdminBox" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2"
Content="Run as administrator"
Margin="0,0,0,8"
Checked="RunAsAdminBox_Changed"
Unchecked="RunAsAdminBox_Changed"/>
<TextBlock Text="Preview" Grid.Row="7" VerticalAlignment="Top" Margin="0,4,8,0"/>
<Border Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="2"
BorderThickness="1"
BorderBrush="{DynamicResource AppBorderBrush}"
Background="{DynamicResource AppSurfaceBrush}"

View File

@@ -616,6 +616,7 @@ public partial class MainWindow : Window
IconPathBox.Text = item.IconPath ?? "";
loadedAutoIconPath = GetAutomaticIconPath(item);
ItemDisplayModeBox.SelectedItem = item.DisplayMode;
RunAsAdminBox.IsChecked = item.RunAsAdmin;
UpdateTargetAvailability();
isLoadingSelection = false;
UpdatePreview();
@@ -633,6 +634,7 @@ public partial class MainWindow : Window
IconPathBox.Text = "";
loadedAutoIconPath = null;
ItemDisplayModeBox.SelectedItem = controller?.Config.DisplayMode;
RunAsAdminBox.IsChecked = false;
UpdateTargetAvailability();
isLoadingSelection = false;
UpdatePreview();
@@ -657,6 +659,7 @@ public partial class MainWindow : Window
{
selectedItem.DisplayMode = itemMode;
}
selectedItem.RunAsAdmin = LauncherController.CanRunAsAdmin(selectedItem.Type) && RunAsAdminBox.IsChecked == true;
if (selectedItem.Type != LauncherItemType.Menu)
{
@@ -966,6 +969,7 @@ public partial class MainWindow : Window
IconPath = item.IconPath,
IsFavorite = item.IsFavorite,
IsDisabled = item.IsDisabled,
RunAsAdmin = item.RunAsAdmin,
DisplayMode = item.DisplayMode,
Children = item.Children.Select(child => DuplicateItem(child, renameRoot: false)).ToList()
};
@@ -1781,6 +1785,20 @@ public partial class MainWindow : Window
ThemeService.Apply(scheme);
}
private void RunAsAdminBox_Changed(object sender, RoutedEventArgs e)
{
if (isLoadingSelection)
{
return;
}
UpdatePreview();
if (selectedItem is not null)
{
StatusText.Text = "Click Save to keep the selected item launch options.";
}
}
private void EnsureAutomaticIconPath()
{
if (TypeBox.SelectedItem is LauncherItemType.Menu)
@@ -1860,6 +1878,8 @@ public partial class MainWindow : Window
IconPath = string.IsNullOrWhiteSpace(IconPathBox.Text) ? null : IconPathBox.Text.Trim(),
IsFavorite = selectedItem.IsFavorite,
IsDisabled = selectedItem.IsDisabled,
RunAsAdmin = LauncherController.CanRunAsAdmin(TypeBox.SelectedItem is LauncherItemType itemType ? itemType : LauncherItemType.App) &&
RunAsAdminBox.IsChecked == true,
DisplayMode = ItemDisplayModeBox.SelectedItem is LauncherDisplayMode mode
? mode
: selectedItem.DisplayMode
@@ -1926,13 +1946,20 @@ public partial class MainWindow : Window
private void UpdateTargetAvailability()
{
bool isMenu = TypeBox.SelectedItem is LauncherItemType.Menu;
bool canRunAsAdmin = TypeBox.SelectedItem is LauncherItemType itemType && LauncherController.CanRunAsAdmin(itemType);
TargetBox.IsEnabled = !isMenu;
ArgumentsBox.IsEnabled = !isMenu;
RunAsAdminBox.IsEnabled = canRunAsAdmin;
if (isMenu && !isLoadingSelection)
{
TargetBox.Text = "";
ArgumentsBox.Text = "";
}
if (!canRunAsAdmin && !isLoadingSelection)
{
RunAsAdminBox.IsChecked = false;
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)

View File

@@ -29,6 +29,8 @@ public sealed class LauncherItem
public bool IsDisabled { get; set; }
public bool RunAsAdmin { get; set; }
public LauncherDisplayMode DisplayMode { get; set; } = LauncherDisplayMode.CompactList;
public List<LauncherItem> Children { get; set; } = [];

View File

@@ -21,6 +21,7 @@ Download the compiled Windows release from:
- Right-click launcher entries to pin or unpin them from the top
- Right-click launcher entries or Settings items to temporarily disable them
- Right-click app/file entries to open their containing folder
- Optional run-as-administrator mode for app and file entries
- Validate missing app, file, and folder targets from Settings
- Export and import selected items or menu sections
- Sort a selected menu or item level alphabetically

View File

@@ -183,6 +183,7 @@ public sealed class LauncherController : IDisposable
IconPath = item.IconPath,
IsFavorite = false,
IsDisabled = false,
RunAsAdmin = item.RunAsAdmin,
DisplayMode = item.DisplayMode,
Children = []
};
@@ -286,6 +287,11 @@ public sealed class LauncherController : IDisposable
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
};
if (item.RunAsAdmin && CanRunAsAdmin(item.Type))
{
startInfo.Verb = "runas";
}
Process.Start(startInfo);
return true;
}
@@ -295,4 +301,9 @@ public sealed class LauncherController : IDisposable
return false;
}
}
public static bool CanRunAsAdmin(LauncherItemType itemType)
{
return itemType is LauncherItemType.App or LauncherItemType.File;
}
}

View File

@@ -12,8 +12,8 @@
<Authors>Ray Berezowski</Authors>
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
<Version>1.0.1</Version>
<AssemblyVersion>1.0.1.17</AssemblyVersion>
<FileVersion>1.0.1.17</FileVersion>
<AssemblyVersion>1.0.1.18</AssemblyVersion>
<FileVersion>1.0.1.18</FileVersion>
<InformationalVersion>1.0.1</InformationalVersion>
</PropertyGroup>

View File

@@ -216,6 +216,7 @@ public partial class LauncherPopup : Window
System.Windows.Controls.ContextMenu contextMenu = new();
contextMenu.Items.Add(CreatePinMenuItem(item));
contextMenu.Items.Add(CreateDisableMenuItem(item));
contextMenu.Items.Add(CreateRunAsAdminMenuItem(item));
contextMenu.Items.Add(CreateOpenContainingFolderMenuItem(item));
contextMenu.Items.Add(CreateEditMenuItem(item));
return contextMenu;
@@ -257,6 +258,25 @@ public partial class LauncherPopup : Window
return disableMenuItem;
}
private System.Windows.Controls.MenuItem CreateRunAsAdminMenuItem(LauncherItem item)
{
System.Windows.Controls.MenuItem runAsAdminMenuItem = new()
{
Header = item.RunAsAdmin ? "Run as Admin: On" : "Run as Admin: Off",
IsEnabled = LauncherController.CanRunAsAdmin(item.Type)
};
runAsAdminMenuItem.Click += (_, e) =>
{
item.RunAsAdmin = !item.RunAsAdmin;
ConfigService.Save(config);
BuildItems();
QueueReposition();
e.Handled = true;
};
return runAsAdminMenuItem;
}
private System.Windows.Controls.MenuItem CreateOpenContainingFolderMenuItem(LauncherItem item)
{
System.Windows.Controls.MenuItem openFolderMenuItem = new()
@@ -453,6 +473,11 @@ public partial class LauncherPopup : Window
AddToolTipLine(panel, "Pinned to top");
}
if (item.RunAsAdmin)
{
AddToolTipLine(panel, "Runs as administrator");
}
return new System.Windows.Controls.ToolTip { Content = panel };
}

View File

@@ -12,6 +12,7 @@
"IconPath": null,
"IsFavorite": false,
"IsDisabled": false,
"RunAsAdmin": false,
"DisplayMode": "CompactList",
"Children": [
{
@@ -22,6 +23,7 @@
"IconPath": "%USERPROFILE%\\Documents",
"IsFavorite": false,
"IsDisabled": false,
"RunAsAdmin": false,
"DisplayMode": "CompactList",
"Children": []
},
@@ -33,6 +35,7 @@
"IconPath": "%USERPROFILE%\\Downloads",
"IsFavorite": false,
"IsDisabled": false,
"RunAsAdmin": false,
"DisplayMode": "CompactList",
"Children": []
}
@@ -46,6 +49,7 @@
"IconPath": null,
"IsFavorite": false,
"IsDisabled": false,
"RunAsAdmin": false,
"DisplayMode": "CompactList",
"Children": [
{
@@ -56,6 +60,7 @@
"IconPath": "notepad.exe",
"IsFavorite": false,
"IsDisabled": false,
"RunAsAdmin": false,
"DisplayMode": "CompactList",
"Children": []
}

View File

@@ -47,6 +47,7 @@ From Settings you can:
- Right-click an item and choose **Pin to Top** to show it first in its menu
- Right-click an item and choose **Disable Item** or **Enable Item** to hide or restore it
- Right-click an app or file item and choose **Open Containing Folder**
- Enable **Run as administrator** for app and file items that need elevation
- Use **Config... > Validate Targets** to check for missing app, file, and folder targets
- Use **Config... > Export Selected Item** or **Import Item** to share one item or menu section
- Right-click an item and choose **Sort This Menu** or **Sort This Level**