hiko-blog

VBA業務改善

MENU

バッチファイル内でPowerShellを利用してウィンドウの不透明度を88%に設定

@echo off

set "WindowTitle=MyWindowTitle"
set "Opacity=88"

powershell.exe -Command "$signature='[DllImport(\"user32.dll\")]public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);';$winapi=Add-Type -MemberDefinition $signature -Name LayeredWindow -Namespace User32 -PassThru; $hwnd=(Get-Process | Where-Object {$_.MainWindowTitle -eq \"%WindowTitle%\"}).MainWindowHandle; $winapi::SetLayeredWindowAttributes($hwnd, 0, (%Opacity% * 255 / 100), 2)"