Skip to content

mimikero

Program / Security etc…

Menu
Menu

Powershellで既に開いているウィンドウを半透明にする

Posted on 2023年10月31日 by mimi

ウィンドウを透明化したいが、それだけのためにフリーソフトは入れたくない。
Powershellで”メモ帳”を含むウィンドウタイトルを対象に透明化する。

透明化後

コード

Add-Type -TypeDefinition @"
    using System;
    using System.Runtime.InteropServices;
    using System.Text;

    public class User32 {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

        public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        [DllImport("user32.dll")]
        public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

        [DllImport("user32.dll")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        public const int GWL_EXSTYLE = -20;
        public const int WS_EX_LAYERED = 0x80000;
        public const int LWA_ALPHA = 0x2;
    }
"@ -Language CSharp

$windowsWithMemoPad = New-Object System.Collections.ArrayList

$enumWindowsCallback = [User32+EnumWindowsProc] {
    param ([System.IntPtr]$hWnd, [System.IntPtr]$lParam)

    $title = New-Object System.Text.StringBuilder 1024
    [User32]::GetWindowText($hWnd, $title, $title.Capacity)
    
    if ($title.ToString().Contains("メモ帳")) {
        $null = $windowsWithMemoPad.Add($hWnd)
    }

    return $true
}

[User32]::EnumWindows($enumWindowsCallback, [System.IntPtr]::Zero)

foreach ($hwnd in $windowsWithMemoPad) {
    $style = [User32]::GetWindowLong($hwnd, [User32]::GWL_EXSTYLE)
    [User32]::SetWindowLong($hwnd, [User32]::GWL_EXSTYLE, ($style -bor [User32]::WS_EX_LAYERED))
    [User32]::SetLayeredWindowAttributes($hwnd, 0, 150, [User32]::LWA_ALPHA) #透明度を指定する(0-255) 
}

if ($windowsWithMemoPad.Count -eq 0) {
    Write-Host "タイトルにメモ帳を含むウィンドウが見つかりませんでした。"
}

透明度やウィンドウ名を調整すればカスタム可能。

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

CAPTCHA


email confirm*

post date*

ads

trends post

Spring Boot と Spring Framework バージョン 対応表まとめ(SpringBoot v2,v3)

Excelデータのスクロールバーが短い現象を保存を使わずに直す

エックスサーバーにLaravelプロジェクトをデプロイ

latest post

  • Cockpit-Docker をubuntu20にインストールする
  • PHPのProcessで日本語パラメータを扱うとsurrogates not allowed となる
  • XServerでexecやshell_execを実行すると、Unable to forkとエラーが出るとき
  • tenable解説 混合リソースの検出
  • tenable解説 WebDAV
  • tenable解説 ディレクトリリスト
  • tenable解説 暗号化されていないパスワードフォーム
  • tenable解説 オートコンプリートのパスワードフィールド
  • tenable解説 CVS/SVN ユーザーの漏洩
  • tenable解説 プライベート IP アドレスの漏洩
  • tenable解説 メールアドレスの漏洩
  • tenable解説 バックアップファイル
  • tenable解説 バックアップディレクトリ
  • tenable解説 共通ファイルの検出
  • tenable解説 共通ディレクトリの検出

カテゴリー

  • Authentication & Session
  • BurpSuite
  • Component Vulnerability
  • Data Exposure
  • HTTP Security Header
  • Lodash
  • Moment.js
  • tenable
  • Web Applications
  • Web Servers
  • 未分類
  • 脆弱性解説
©2025 mimikero | WordPress Theme by Superbthemes.com