Forum Discussion

Devika_Sivakumar's avatar
Devika_Sivakumar
Copper Contributor
Apr 24, 2024

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

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

  • Andres-Bohren's avatar
    Andres-Bohren
    Steel Contributor

    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

Resources