Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active January 5, 2024 08:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grenade/ed8dd77ae8eeb5b4a3c1cfd66e9c8ae7 to your computer and use it in GitHub Desktop.
Save grenade/ed8dd77ae8eeb5b4a3c1cfd66e9c8ae7 to your computer and use it in GitHub Desktop.
make powershell and cmd terminals transparent
if (-not Test-Path -Path $profile) { New-Item -path $profile -type file -force }
Add-Content -Path $profile -Value '$user32 = Add-Type -Name ''User32'' -Namespace ''Win32'' -PassThru -MemberDefinition ''[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);[DllImport("user32.dll", SetLastError = true)]public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, int bAlpha, uint dwFlags);'''
Add-Content -Path $profile -Value 'Get-Process | Where-Object { @(''powershell'', ''cmd'') -contains $_.ProcessName } | % { $user32::SetWindowLong($_.MainWindowHandle, -20, ($user32::GetWindowLong($_.MainWindowHandle, -20) -bor 0x80000)) | Out-Null;$user32::SetLayeredWindowAttributes($_.MainWindowHandle, 0, 200, 0x02) | Out-Null }'
function Set-WindowTransparency {
param (
[ValidateRange(0, 255)]
[int] $transparency = 200,
[string[]] $processes = @('powershell', 'cmd')
)
$user32 = Add-Type -Name 'user32' -Namespace 'Win32' -PassThru -MemberDefinition @'
[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);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, int bAlpha, uint dwFlags);
'@
Get-Process | Where-Object { $processes -contains $_.ProcessName } | % {
$wl = $user32::GetWindowLong($_.MainWindowHandle, -20)
$user32::SetWindowLong($_.MainWindowHandle, -20, ($wl -bor 0x80000)) | Out-Null
$user32::SetLayeredWindowAttributes($_.MainWindowHandle, 0, $transparency, 0x02) | Out-Null
}
}
@Tiberriver256
Copy link

This is awesome and it does work for other windows too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment