dotnet / dotnet/wpf

New feature: Add property to JumpTask to allow for elevated jump list entry

Open
#950 1 comment 0 reactions 0 assignees View on GitHub
Enhancement Requested
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

Background: PowerShell Core has a lot of custom code [here](https://github.com/PowerShell/PowerShell/tree/master/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList) that makes COM calls to the Windows API for creating a jumplist entry to run PowerShell as an Administrator. However, in both .Net Core 2.1 and .Net Core 3.0-preview5, it has been observed that the CLR fails sporadically with a fatal error: https://github.com/PowerShell/PowerShell/issues/9295

WPF has APIs for creating a taskbar jump list but not for launching the application as elevated. PowerShell would therefore like to rather use WPF to minimize the amount of (possibly buggy code).

Proposal:

We add a boolean property to `JumpTask` (I don't mind about its name, what about `RequestElevation`?) so that when when `JumpList.Apply()` gets called the application will be elevated. The default will be to start unelevated.
The implementation will be quite simple, all we need to do is to use `SLDF_RUNAS_USER` enum on [SHELL_LINK_DATA_FLAGS](https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ne-shlobj_core-shell_link_data_flags). We will be calling [IShellLinkDataList::GetFlag](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ishelllinkdatalist-getflags)`, adding the enum value using XOR and then call [IShellLinkDataList::SetFlags](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ishelllinkdatalist-setflags) on the `shellLink` object of type `IShellLinkW` in JumpList.

Are you OK with this proposal that includes no breaking change?
I would first code this from a theoretical perspective, open a draft PR and from then on I would be grateful for some assistance for being able to test it and will have to do some homework to get familiar with this repo (I have never committed to .Net Core before although I use it a lot)

In terms of the usage, do you expect the process that is calling those APIs to be in STA mode or does it not matter? WPF is STA by default AFAIK but PowerShell Core is a console app and currently still in MTA mode due to .Net Core not offering STA yet in 2.1. There is a check for STA in WPF [https://github.com/dotnet/wpf/blob/ae1790531c3b993b56eba8b1f0dd395a3ed7de75/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L564](https://github.com/dotnet/wpf/blob/ae1790531c3b993b56eba8b1f0dd395a3ed7de75/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L564) but I am not sure if this is due to WPF or the COM calls being made

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.