mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 17:38:19 +02:00
Added set-wallpaper.ps1
This commit is contained in:
parent
dcc52122c4
commit
2e12acbf92
@ -65,6 +65,7 @@ send-email.ps1, sends an email message
|
|||||||
send-tcp.ps1, sends a TCP message to the given IP address and port
|
send-tcp.ps1, sends a TCP message to the given IP address and port
|
||||||
send-udp.ps1, sends a UDP datagram message to the given IP address and port
|
send-udp.ps1, sends a UDP datagram message to the given IP address and port
|
||||||
set-timer.ps1, sets a timer for a countdown
|
set-timer.ps1, sets a timer for a countdown
|
||||||
|
set-wallpaper.ps1, sets the given image as wallpaper
|
||||||
SHA1.ps1, prints the SHA1 checksum of the given file
|
SHA1.ps1, prints the SHA1 checksum of the given file
|
||||||
SHA256.ps1, prints the SHA256 checksum of the given file
|
SHA256.ps1, prints the SHA256 checksum of the given file
|
||||||
simulate-matrix.ps1, simulates the Matrix (fun)
|
simulate-matrix.ps1, simulates the Matrix (fun)
|
||||||
|
|
@ -73,6 +73,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
|
|||||||
* [send-tcp.ps1](Scripts/send-udp.ps1) - sends a TCP message to the given IP address and port
|
* [send-tcp.ps1](Scripts/send-udp.ps1) - sends a TCP message to the given IP address and port
|
||||||
* [send-udp.ps1](Scripts/send-udp.ps1) - sends a UDP datagram message to the given IP address and port
|
* [send-udp.ps1](Scripts/send-udp.ps1) - sends a UDP datagram message to the given IP address and port
|
||||||
* [set-timer.ps1](Scripts/set-timer.ps1) - sets a timer for a countdown
|
* [set-timer.ps1](Scripts/set-timer.ps1) - sets a timer for a countdown
|
||||||
|
* [set-wallpaper.ps1](Scripts/set-wallpaper.ps1) - sets the given image as wallpaper
|
||||||
* [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file
|
* [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file
|
||||||
* [SHA256.ps1](Scripts/SHA256.ps1) - prints the SHA256 checksum of the given file
|
* [SHA256.ps1](Scripts/SHA256.ps1) - prints the SHA256 checksum of the given file
|
||||||
* [simulate-matrix.ps1](Scripts/simulate-matrix.ps1) - simulates the Matrix (fun)
|
* [simulate-matrix.ps1](Scripts/simulate-matrix.ps1) - simulates the Matrix (fun)
|
||||||
|
95
Scripts/set-wallpaper.ps1
Normal file
95
Scripts/set-wallpaper.ps1
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#!/snap/bin/powershell
|
||||||
|
<#
|
||||||
|
.SYNTAX ./set-wallpaper.ps1 [<image-file>] [<style>]
|
||||||
|
.DESCRIPTION sets the given image file as wallpaper
|
||||||
|
.LINK https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param([string]$ImageFile = "", [string]$Style = "Fit")
|
||||||
|
|
||||||
|
function SetWallPaper {
|
||||||
|
<#
|
||||||
|
|
||||||
|
.SYNOPSIS
|
||||||
|
Applies a specified wallpaper to the current user's desktop
|
||||||
|
|
||||||
|
.PARAMETER Image
|
||||||
|
Provide the exact path to the image
|
||||||
|
|
||||||
|
.PARAMETER Style
|
||||||
|
Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span)
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Set-WallPaper -Image "C:\Wallpaper\Default.jpg"
|
||||||
|
Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit
|
||||||
|
|
||||||
|
#>
|
||||||
|
|
||||||
|
param (
|
||||||
|
[parameter(Mandatory=$True)]
|
||||||
|
# Provide path to image
|
||||||
|
[string]$Image,
|
||||||
|
# Provide wallpaper style that you would like applied
|
||||||
|
[parameter(Mandatory=$False)]
|
||||||
|
[ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')]
|
||||||
|
[string]$Style
|
||||||
|
)
|
||||||
|
|
||||||
|
$WallpaperStyle = Switch ($Style) {
|
||||||
|
|
||||||
|
"Fill" {"10"}
|
||||||
|
"Fit" {"6"}
|
||||||
|
"Stretch" {"2"}
|
||||||
|
"Tile" {"0"}
|
||||||
|
"Center" {"0"}
|
||||||
|
"Span" {"22"}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
If($Style -eq "Tile") {
|
||||||
|
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
|
||||||
|
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
|
||||||
|
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Add-Type -TypeDefinition @"
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
public class Params
|
||||||
|
{
|
||||||
|
[DllImport("User32.dll",CharSet=CharSet.Unicode)]
|
||||||
|
public static extern int SystemParametersInfo (Int32 uAction,
|
||||||
|
Int32 uParam,
|
||||||
|
String lpvParam,
|
||||||
|
Int32 fuWinIni);
|
||||||
|
}
|
||||||
|
"@
|
||||||
|
|
||||||
|
$SPI_SETDESKWALLPAPER = 0x0014
|
||||||
|
$UpdateIniFile = 0x01
|
||||||
|
$SendChangeEvent = 0x02
|
||||||
|
|
||||||
|
$fWinIni = $UpdateIniFile -bor $SendChangeEvent
|
||||||
|
|
||||||
|
$ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($ImageFile -eq "" ) {
|
||||||
|
$ImageFile = read-host "Enter path to image file"
|
||||||
|
}
|
||||||
|
SetWallPaper -Image $ImageFile -Style $Style
|
||||||
|
exit 0
|
||||||
|
} catch {
|
||||||
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user