Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/msr8/attiny85
Browse files Browse the repository at this point in the history
kk
  • Loading branch information
msr8 committed Dec 1, 2022
2 parents dce8ee1 + 6162242 commit 1c04843
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Shell Scripts/powershell/wallpaper_troll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Defines the Update-Wallpaper command
Function Update-Wallpaper {
Param(
[Parameter(Mandatory=$true)]
$Path,
[ValidateSet('Center','Stretch','Fill','Tile','Fit')]
$Style
)
Try {
if (-not ([System.Management.Automation.PSTypeName]'Wallpaper.Setter').Type) {
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper {
public enum Style : int {
Center, Stretch, Fill, Fit, Tile
}
public class Setter {
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path, Wallpaper.Style style ) {
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
switch( style ) {
case Style.Tile :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "1") ;
break;
case Style.Center :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Stretch :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Fill :
key.SetValue(@"WallpaperStyle", "10") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Fit :
key.SetValue(@"WallpaperStyle", "6") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
}
key.Close();
}
}
}
"@ -ErrorAction Stop
}
}
Catch {
Write-Warning -Message "Wallpaper not changed because $($_.Exception.Message)"
}
[Wallpaper.Setter]::SetWallpaper( $Path, $Style )
}


# Defines the screenshot command, https://stackoverflow.com/a/2970339/17002774
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}


# Waits sometime as to not get the powershell window in the frame
Start-Sleep 1

# Gets the dimensions of screenshot, https://stackoverflow.com/a/35965782/17002774
$vc = Get-WmiObject -class "Win32_VideoController"
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, $vc.CurrentHorizontalResolution[1], $vc.CurrentVerticalResolution[1])

# Takes the screenshot
$ss_fp = "$env:TEMP\1987215.png"
screenshot $bounds $ss_fp

# Sets it as the wallpaper
Update-Wallpaper -Path $ss_fp -Style Stretch
Update-Wallpaper -Path $ss_fp -Style Stretch

# Deletes it
Remove-Item $ss_fp

# Hides the desktop icons, https://superuser.com/questions/1368139/disable-show-desktop-icons-in-windows-with-powershell
$Path="HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name "HideIcons" -Value 1

# Hides the taskbar, https://stackoverflow.com/a/47202007/17002774
$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'
$v=(Get-ItemProperty -Path $p).Settings
$v[8]=3
Set-ItemProperty -Path $p -Name Settings -Value $v

# Restarts the "explorer" process so that our changes take effect
Get-Process "explorer"| Stop-Process







0 comments on commit 1c04843

Please sign in to comment.