How to set desktop background from spotlight to picture option using powershell script

Copper Contributor

How to set desktop background from spotlight to picture option by setting registry key using powershell script

3 Replies

Hi @Devika_Sivakumar 

 

Images from here? https://windows10spotlight.com/

 

#Invoke-WebRequest
$return = Invoke-WebRequest -Uri "https://windows10spotlight.com" -UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
#List Images
$return.images.src

#Take first Image1URL
$Image1URL = $return.images.src[0]

#Download File
Invoke-WebRequest -Uri $Image1URL -UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" -OutFile "C:\Temp\Background.jpg"

#Set Background Image
$setwallpapersrc=@"
using System.Runtime.InteropServices;

public class Wallpaper
{
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)
{
SystemParametersInfo(SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange);
}
}
"@
Add-Type -TypeDefinition $setwallpapersrc
[Wallpaper]::SetWallpaper("C:\Temp\Background.jpg")

 

Kind Regards

Andres

@Andres Bohren 

Thankyou for the reply , but I need powershell script to get option as picture under background for choosing instead of spotlight. Please find the attachment below

Hi @Devika_Sivakumar 

 

Try to set it here

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers

AndresBohren_0-1714033588337.png

 

Set-ItemProperty 

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-itemproperty... 

 

Kind Regards

Andres