diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/NativeMethods.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/NativeMethods.cs
index b0a6e4355b..c158e51f1a 100644
--- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/NativeMethods.cs
+++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/NativeMethods.cs
@@ -645,9 +645,19 @@ namespace Microsoft.Plugin.WindowWalker.Components
///
/// GetWindowLong index to retrieves the extended window styles.
///
- [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Matching interop var")]
public const int GWL_EXSTYLE = -20;
+ ///
+ /// A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu)
+ /// or when the user chooses the maximize button, minimize button, restore button, or close button.
+ ///
+ public const int WM_SYSCOMMAND = 0x0112;
+
+ ///
+ /// Restores the window to its normal position and size.
+ ///
+ public const int SC_RESTORE = 0xf120;
+
///
/// The following are the extended window styles
///
@@ -877,5 +887,8 @@ namespace Microsoft.Plugin.WindowWalker.Components
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
+
+ [DllImport("user32.dll")]
+ public static extern int SendMessage(IntPtr hWnd, int msg, int wParam);
}
}
diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/Window.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/Window.cs
index 7e28b738fc..59bf6471e3 100644
--- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/Window.cs
+++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/Window.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation
+// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -6,15 +6,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
namespace Microsoft.Plugin.WindowWalker.Components
{
@@ -259,7 +254,11 @@ namespace Microsoft.Plugin.WindowWalker.Components
}
else
{
- NativeMethods.ShowWindow(Hwnd, NativeMethods.ShowWindowCommands.Restore);
+ if (!NativeMethods.ShowWindow(Hwnd, NativeMethods.ShowWindowCommands.Restore))
+ {
+ // ShowWindow doesn't work if the process is running elevated: fallback to SendMessage
+ _ = NativeMethods.SendMessage(Hwnd, NativeMethods.WM_SYSCOMMAND, NativeMethods.SC_RESTORE);
+ }
}
NativeMethods.FlashWindow(Hwnd, true);
@@ -318,7 +317,7 @@ namespace Microsoft.Plugin.WindowWalker.Components
{
uint processId = GetProcessIDFromWindowHandle(hwnd);
ProcessID = processId;
- IntPtr processHandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.AllAccess, true, (int)processId);
+ IntPtr processHandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.QueryLimitedInformation, true, (int)processId);
StringBuilder processName = new StringBuilder(MaximumFileNameLength);
if (NativeMethods.GetProcessImageFileName(processHandle, processName, MaximumFileNameLength) != 0)