Add run as administrator option
This commit is contained in:
@@ -134,6 +134,7 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<TextBlock Text="Hotkey" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
<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"
|
<ComboBox x:Name="ItemDisplayModeBox" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2"
|
||||||
Margin="0,0,0,8" SelectionChanged="ItemDisplayModeBox_SelectionChanged"/>
|
Margin="0,0,0,8" SelectionChanged="ItemDisplayModeBox_SelectionChanged"/>
|
||||||
|
|
||||||
<TextBlock Text="Preview" Grid.Row="6" VerticalAlignment="Top" Margin="0,4,8,0"/>
|
<TextBlock Text="Launch Options" Grid.Row="6" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
<Border Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2"
|
<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"
|
BorderThickness="1"
|
||||||
BorderBrush="{DynamicResource AppBorderBrush}"
|
BorderBrush="{DynamicResource AppBorderBrush}"
|
||||||
Background="{DynamicResource AppSurfaceBrush}"
|
Background="{DynamicResource AppSurfaceBrush}"
|
||||||
|
|||||||
@@ -616,6 +616,7 @@ public partial class MainWindow : Window
|
|||||||
IconPathBox.Text = item.IconPath ?? "";
|
IconPathBox.Text = item.IconPath ?? "";
|
||||||
loadedAutoIconPath = GetAutomaticIconPath(item);
|
loadedAutoIconPath = GetAutomaticIconPath(item);
|
||||||
ItemDisplayModeBox.SelectedItem = item.DisplayMode;
|
ItemDisplayModeBox.SelectedItem = item.DisplayMode;
|
||||||
|
RunAsAdminBox.IsChecked = item.RunAsAdmin;
|
||||||
UpdateTargetAvailability();
|
UpdateTargetAvailability();
|
||||||
isLoadingSelection = false;
|
isLoadingSelection = false;
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
@@ -633,6 +634,7 @@ public partial class MainWindow : Window
|
|||||||
IconPathBox.Text = "";
|
IconPathBox.Text = "";
|
||||||
loadedAutoIconPath = null;
|
loadedAutoIconPath = null;
|
||||||
ItemDisplayModeBox.SelectedItem = controller?.Config.DisplayMode;
|
ItemDisplayModeBox.SelectedItem = controller?.Config.DisplayMode;
|
||||||
|
RunAsAdminBox.IsChecked = false;
|
||||||
UpdateTargetAvailability();
|
UpdateTargetAvailability();
|
||||||
isLoadingSelection = false;
|
isLoadingSelection = false;
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
@@ -657,6 +659,7 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
selectedItem.DisplayMode = itemMode;
|
selectedItem.DisplayMode = itemMode;
|
||||||
}
|
}
|
||||||
|
selectedItem.RunAsAdmin = LauncherController.CanRunAsAdmin(selectedItem.Type) && RunAsAdminBox.IsChecked == true;
|
||||||
|
|
||||||
if (selectedItem.Type != LauncherItemType.Menu)
|
if (selectedItem.Type != LauncherItemType.Menu)
|
||||||
{
|
{
|
||||||
@@ -966,6 +969,7 @@ public partial class MainWindow : Window
|
|||||||
IconPath = item.IconPath,
|
IconPath = item.IconPath,
|
||||||
IsFavorite = item.IsFavorite,
|
IsFavorite = item.IsFavorite,
|
||||||
IsDisabled = item.IsDisabled,
|
IsDisabled = item.IsDisabled,
|
||||||
|
RunAsAdmin = item.RunAsAdmin,
|
||||||
DisplayMode = item.DisplayMode,
|
DisplayMode = item.DisplayMode,
|
||||||
Children = item.Children.Select(child => DuplicateItem(child, renameRoot: false)).ToList()
|
Children = item.Children.Select(child => DuplicateItem(child, renameRoot: false)).ToList()
|
||||||
};
|
};
|
||||||
@@ -1781,6 +1785,20 @@ public partial class MainWindow : Window
|
|||||||
ThemeService.Apply(scheme);
|
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()
|
private void EnsureAutomaticIconPath()
|
||||||
{
|
{
|
||||||
if (TypeBox.SelectedItem is LauncherItemType.Menu)
|
if (TypeBox.SelectedItem is LauncherItemType.Menu)
|
||||||
@@ -1860,6 +1878,8 @@ public partial class MainWindow : Window
|
|||||||
IconPath = string.IsNullOrWhiteSpace(IconPathBox.Text) ? null : IconPathBox.Text.Trim(),
|
IconPath = string.IsNullOrWhiteSpace(IconPathBox.Text) ? null : IconPathBox.Text.Trim(),
|
||||||
IsFavorite = selectedItem.IsFavorite,
|
IsFavorite = selectedItem.IsFavorite,
|
||||||
IsDisabled = selectedItem.IsDisabled,
|
IsDisabled = selectedItem.IsDisabled,
|
||||||
|
RunAsAdmin = LauncherController.CanRunAsAdmin(TypeBox.SelectedItem is LauncherItemType itemType ? itemType : LauncherItemType.App) &&
|
||||||
|
RunAsAdminBox.IsChecked == true,
|
||||||
DisplayMode = ItemDisplayModeBox.SelectedItem is LauncherDisplayMode mode
|
DisplayMode = ItemDisplayModeBox.SelectedItem is LauncherDisplayMode mode
|
||||||
? mode
|
? mode
|
||||||
: selectedItem.DisplayMode
|
: selectedItem.DisplayMode
|
||||||
@@ -1926,13 +1946,20 @@ public partial class MainWindow : Window
|
|||||||
private void UpdateTargetAvailability()
|
private void UpdateTargetAvailability()
|
||||||
{
|
{
|
||||||
bool isMenu = TypeBox.SelectedItem is LauncherItemType.Menu;
|
bool isMenu = TypeBox.SelectedItem is LauncherItemType.Menu;
|
||||||
|
bool canRunAsAdmin = TypeBox.SelectedItem is LauncherItemType itemType && LauncherController.CanRunAsAdmin(itemType);
|
||||||
TargetBox.IsEnabled = !isMenu;
|
TargetBox.IsEnabled = !isMenu;
|
||||||
ArgumentsBox.IsEnabled = !isMenu;
|
ArgumentsBox.IsEnabled = !isMenu;
|
||||||
|
RunAsAdminBox.IsEnabled = canRunAsAdmin;
|
||||||
if (isMenu && !isLoadingSelection)
|
if (isMenu && !isLoadingSelection)
|
||||||
{
|
{
|
||||||
TargetBox.Text = "";
|
TargetBox.Text = "";
|
||||||
ArgumentsBox.Text = "";
|
ArgumentsBox.Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canRunAsAdmin && !isLoadingSelection)
|
||||||
|
{
|
||||||
|
RunAsAdminBox.IsChecked = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public sealed class LauncherItem
|
|||||||
|
|
||||||
public bool IsDisabled { get; set; }
|
public bool IsDisabled { get; set; }
|
||||||
|
|
||||||
|
public bool RunAsAdmin { get; set; }
|
||||||
|
|
||||||
public LauncherDisplayMode DisplayMode { get; set; } = LauncherDisplayMode.CompactList;
|
public LauncherDisplayMode DisplayMode { get; set; } = LauncherDisplayMode.CompactList;
|
||||||
|
|
||||||
public List<LauncherItem> Children { get; set; } = [];
|
public List<LauncherItem> Children { get; set; } = [];
|
||||||
|
|||||||
@@ -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 to pin or unpin them from the top
|
||||||
- Right-click launcher entries or Settings items to temporarily disable them
|
- Right-click launcher entries or Settings items to temporarily disable them
|
||||||
- Right-click app/file entries to open their containing folder
|
- 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
|
- Validate missing app, file, and folder targets from Settings
|
||||||
- Export and import selected items or menu sections
|
- Export and import selected items or menu sections
|
||||||
- Sort a selected menu or item level alphabetically
|
- Sort a selected menu or item level alphabetically
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ public sealed class LauncherController : IDisposable
|
|||||||
IconPath = item.IconPath,
|
IconPath = item.IconPath,
|
||||||
IsFavorite = false,
|
IsFavorite = false,
|
||||||
IsDisabled = false,
|
IsDisabled = false,
|
||||||
|
RunAsAdmin = item.RunAsAdmin,
|
||||||
DisplayMode = item.DisplayMode,
|
DisplayMode = item.DisplayMode,
|
||||||
Children = []
|
Children = []
|
||||||
};
|
};
|
||||||
@@ -286,6 +287,11 @@ public sealed class LauncherController : IDisposable
|
|||||||
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (item.RunAsAdmin && CanRunAsAdmin(item.Type))
|
||||||
|
{
|
||||||
|
startInfo.Verb = "runas";
|
||||||
|
}
|
||||||
|
|
||||||
Process.Start(startInfo);
|
Process.Start(startInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -295,4 +301,9 @@ public sealed class LauncherController : IDisposable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CanRunAsAdmin(LauncherItemType itemType)
|
||||||
|
{
|
||||||
|
return itemType is LauncherItemType.App or LauncherItemType.File;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
<Authors>Ray Berezowski</Authors>
|
<Authors>Ray Berezowski</Authors>
|
||||||
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
|
||||||
<Version>1.0.1</Version>
|
<Version>1.0.1</Version>
|
||||||
<AssemblyVersion>1.0.1.17</AssemblyVersion>
|
<AssemblyVersion>1.0.1.18</AssemblyVersion>
|
||||||
<FileVersion>1.0.1.17</FileVersion>
|
<FileVersion>1.0.1.18</FileVersion>
|
||||||
<InformationalVersion>1.0.1</InformationalVersion>
|
<InformationalVersion>1.0.1</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ public partial class LauncherPopup : Window
|
|||||||
System.Windows.Controls.ContextMenu contextMenu = new();
|
System.Windows.Controls.ContextMenu contextMenu = new();
|
||||||
contextMenu.Items.Add(CreatePinMenuItem(item));
|
contextMenu.Items.Add(CreatePinMenuItem(item));
|
||||||
contextMenu.Items.Add(CreateDisableMenuItem(item));
|
contextMenu.Items.Add(CreateDisableMenuItem(item));
|
||||||
|
contextMenu.Items.Add(CreateRunAsAdminMenuItem(item));
|
||||||
contextMenu.Items.Add(CreateOpenContainingFolderMenuItem(item));
|
contextMenu.Items.Add(CreateOpenContainingFolderMenuItem(item));
|
||||||
contextMenu.Items.Add(CreateEditMenuItem(item));
|
contextMenu.Items.Add(CreateEditMenuItem(item));
|
||||||
return contextMenu;
|
return contextMenu;
|
||||||
@@ -257,6 +258,25 @@ public partial class LauncherPopup : Window
|
|||||||
return disableMenuItem;
|
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)
|
private System.Windows.Controls.MenuItem CreateOpenContainingFolderMenuItem(LauncherItem item)
|
||||||
{
|
{
|
||||||
System.Windows.Controls.MenuItem openFolderMenuItem = new()
|
System.Windows.Controls.MenuItem openFolderMenuItem = new()
|
||||||
@@ -453,6 +473,11 @@ public partial class LauncherPopup : Window
|
|||||||
AddToolTipLine(panel, "Pinned to top");
|
AddToolTipLine(panel, "Pinned to top");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.RunAsAdmin)
|
||||||
|
{
|
||||||
|
AddToolTipLine(panel, "Runs as administrator");
|
||||||
|
}
|
||||||
|
|
||||||
return new System.Windows.Controls.ToolTip { Content = panel };
|
return new System.Windows.Controls.ToolTip { Content = panel };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"IconPath": null,
|
"IconPath": null,
|
||||||
"IsFavorite": false,
|
"IsFavorite": false,
|
||||||
"IsDisabled": false,
|
"IsDisabled": false,
|
||||||
|
"RunAsAdmin": false,
|
||||||
"DisplayMode": "CompactList",
|
"DisplayMode": "CompactList",
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
"IconPath": "%USERPROFILE%\\Documents",
|
"IconPath": "%USERPROFILE%\\Documents",
|
||||||
"IsFavorite": false,
|
"IsFavorite": false,
|
||||||
"IsDisabled": false,
|
"IsDisabled": false,
|
||||||
|
"RunAsAdmin": false,
|
||||||
"DisplayMode": "CompactList",
|
"DisplayMode": "CompactList",
|
||||||
"Children": []
|
"Children": []
|
||||||
},
|
},
|
||||||
@@ -33,6 +35,7 @@
|
|||||||
"IconPath": "%USERPROFILE%\\Downloads",
|
"IconPath": "%USERPROFILE%\\Downloads",
|
||||||
"IsFavorite": false,
|
"IsFavorite": false,
|
||||||
"IsDisabled": false,
|
"IsDisabled": false,
|
||||||
|
"RunAsAdmin": false,
|
||||||
"DisplayMode": "CompactList",
|
"DisplayMode": "CompactList",
|
||||||
"Children": []
|
"Children": []
|
||||||
}
|
}
|
||||||
@@ -46,6 +49,7 @@
|
|||||||
"IconPath": null,
|
"IconPath": null,
|
||||||
"IsFavorite": false,
|
"IsFavorite": false,
|
||||||
"IsDisabled": false,
|
"IsDisabled": false,
|
||||||
|
"RunAsAdmin": false,
|
||||||
"DisplayMode": "CompactList",
|
"DisplayMode": "CompactList",
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
@@ -56,6 +60,7 @@
|
|||||||
"IconPath": "notepad.exe",
|
"IconPath": "notepad.exe",
|
||||||
"IsFavorite": false,
|
"IsFavorite": false,
|
||||||
"IsDisabled": false,
|
"IsDisabled": false,
|
||||||
|
"RunAsAdmin": false,
|
||||||
"DisplayMode": "CompactList",
|
"DisplayMode": "CompactList",
|
||||||
"Children": []
|
"Children": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 **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 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**
|
- 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... > 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
|
- 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**
|
- Right-click an item and choose **Sort This Menu** or **Sort This Level**
|
||||||
|
|||||||
Reference in New Issue
Block a user