mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Window Walker] Path for elevated process (#15186)
This commit is contained in:
committed by
GitHub
parent
67933a8470
commit
cf0c45a319
@@ -645,9 +645,19 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// GetWindowLong index to retrieves the extended window styles.
|
/// GetWindowLong index to retrieves the extended window styles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Matching interop var")]
|
|
||||||
public const int GWL_EXSTYLE = -20;
|
public const int GWL_EXSTYLE = -20;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public const int WM_SYSCOMMAND = 0x0112;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restores the window to its normal position and size.
|
||||||
|
/// </summary>
|
||||||
|
public const int SC_RESTORE = 0xf120;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The following are the extended window styles
|
/// The following are the extended window styles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -877,5 +887,8 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
|||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
|
public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
@@ -6,15 +6,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
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
|
namespace Microsoft.Plugin.WindowWalker.Components
|
||||||
{
|
{
|
||||||
@@ -259,7 +254,11 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
|||||||
}
|
}
|
||||||
else
|
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);
|
NativeMethods.FlashWindow(Hwnd, true);
|
||||||
@@ -318,7 +317,7 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
|||||||
{
|
{
|
||||||
uint processId = GetProcessIDFromWindowHandle(hwnd);
|
uint processId = GetProcessIDFromWindowHandle(hwnd);
|
||||||
ProcessID = processId;
|
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);
|
StringBuilder processName = new StringBuilder(MaximumFileNameLength);
|
||||||
|
|
||||||
if (NativeMethods.GetProcessImageFileName(processHandle, processName, MaximumFileNameLength) != 0)
|
if (NativeMethods.GetProcessImageFileName(processHandle, processName, MaximumFileNameLength) != 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user