アプリケーションを最小化PowerShellでメモ帳が起動していたら最小化したいのですが複数起動していると最小化しませんどのようにすればよいでしょうかif (Get-Process notepad -ErrorAction SilentlyContinue) {$Signature = @\u0026quot;[DllImport(\u0026quot;user32.dll\u0026quot;)]public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);\u0026quot;@$ShowWindowAsync = Add-Type -MemberDefinition $Signature -Name \u0026quot;Win32ShowWindowAsync\u0026quot; -Namespace Win32Functions -PassThru$ShowWindowAsync::ShowWindowAsync((Get-Process|?{$_.MainWindowTitle -like \u0026quot;*メモ帳*\u0026quot;}).MainWindowHandle, 2)}

1件の回答

回答を書く

1029057

2026-02-07 20:25

+ フォロー

Copilotの回答



Add-Type @\u0026quot;

using System;

using System.Runtime.InteropServices;

public class Win32 {

    [DllImport(\u0026quot;user32.dll\u0026quot;)]

    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

}

\u0026quot;@



# 最小化の定数

$SW_MINIMIZE = 6



# notepad.exe のすべてのプロセスを取得

$notepads = Get-Process notepad -ErrorAction SilentlyContinue



foreach ($np in $notepads) {

    if ($np.MainWindowHandle -ne 0) {

        # ウィンドウを最小化

        [Win32]::ShowWindow($np.MainWindowHandle, $SW_MINIMIZE)

    }

}

うったえる有益だ(0シェアするブックマークする

関連質問

Copyright © 2026 AQ188.com All Rights Reserved.

博識 著作権所有