File tree Expand file tree Collapse file tree
src/Microsoft.PowerShell.ConsoleHost Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ internal static class TaskbarJumpList
1212 {
1313 internal static void CreateElevatedEntry ( string title )
1414 {
15- // check startupInfo to know if the current shell owns a window before proceeding
15+ // Check startupInfo first to know if the current shell is interactive and owns a window before proceeding
16+ // This check is fast (less than 1ms) and allows for quick-exit
1617 GetStartupInfo ( out StartUpInfo startupInfo ) ;
1718 var STARTF_USESHOWWINDOW = 0x00000001 ;
1819 var SW_HIDE = 0 ;
Original file line number Diff line number Diff line change 2626using Dbg = System . Management . Automation . Diagnostics ;
2727using ConsoleHandle = Microsoft . Win32 . SafeHandles . SafeFileHandle ;
2828using System . Management . Automation . Tracing ;
29+ using System . Threading . Tasks ;
2930#if LEGACYTELEMETRY
3031using Microsoft . PowerShell . Telemetry . Internal ;
3132#endif
@@ -120,10 +121,6 @@ internal static int Start(
120121 }
121122#endif
122123
123- #if ! UNIX
124- Microsoft . PowerShell . TaskbarJumpList . CreateElevatedEntry ( ConsoleHostStrings . RunAsAdministrator ) ;
125- #endif
126-
127124 // put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
128125 string path = Environment . GetEnvironmentVariable ( "PATH" ) ;
129126 if ( path != null )
@@ -214,6 +211,16 @@ internal static int Start(
214211 return ExitCodeBadCommandLineParameter ;
215212 }
216213
214+ #if ! UNIX
215+ // Creating a JumpList entry takes around 55ms when the PowerShell process is interactive and
216+ // owns the current window (otherwise it does a fast exit anyway). Since there is no 'GET' like API,
217+ // we always have to execute this call because we do not know if it has been created yet.
218+ // The JumpList does persist as long as the filepath of the executable does not change but there
219+ // could be disruptions to it like e.g. the bi-annual Windows update, we decided to
220+ // not over-optimize this and always create the JumpList as a non-blocking background task instead.
221+ Task . Run ( ( ) => TaskbarJumpList . CreateElevatedEntry ( ConsoleHostStrings . RunAsAdministrator ) ) ;
222+ #endif
223+
217224 // First check for and handle PowerShell running in a server mode.
218225 if ( s_cpp . ServerMode )
219226 {
You can’t perform that action at this time.
0 commit comments