Last active
January 5, 2024 08:25
-
-
Save grenade/ed8dd77ae8eeb5b4a3c1cfd66e9c8ae7 to your computer and use it in GitHub Desktop.
make powershell and cmd terminals transparent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome and it does work for other windows too!