0

I created a script to change the wallpaper on Windows laptops. When tested locally via PowerShell, it works as expected, successfully changing the wallpaper. However, deploying the same script via Intune only downloads the image to the specified path, but the wallpaper does not update.

# Define the URL of the wallpaper image and the destination folder
$WallpaperURL = "https://path\to\wallpaper"
$DestinationFolder = "C:\ProgramData\Wallpaper"
$WallpaperPath = "$DestinationFolder\wallpaper.jpg"

# Ensure the destination folder exists
if (-not (Test-Path -Path $DestinationFolder)) {
    New-Item -Path $DestinationFolder -ItemType Directory -Force
}

# Download the wallpaper image securely
try {
    Write-Host "Downloading wallpaper from $WallpaperURL..."
    Invoke-WebRequest -Uri $WallpaperURL -OutFile $WallpaperPath -TimeoutSec 30
    Write-Host "Wallpaper downloaded successfully."
} catch {
    Write-Host "Failed to download the wallpaper: $_"
    exit 1
}

# Set the wallpaper registry key
try {
    Write-Host "Setting the wallpaper..."
    Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name "Wallpaper" -Value $WallpaperPath
    Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\" -Name "WallpaperStyle" -Value 2  # 2 = Stretched
    Write-Host "Wallpaper set successfully."
} catch {
    Write-Host "Failed to set the wallpaper: $_"
    exit 1
}

# Refresh the desktop to apply the changes
try {
    Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public class Wallpaper {
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
'@

    # Correct method call with proper closing parenthesis
    [Wallpaper]::SystemParametersInfo(20, 0, $WallpaperPath, 0x01 -bor 0x02)
    Write-Host "Wallpaper refresh applied successfully."
} catch {
    Write-Host "Failed to refresh the wallpaper: $_"
    exit 1
}

# Confirm completion
Write-Host "Wallpaper change process completed."

1 Answer 1

0

Pay attention to settings of the script: the parameter "Run this script using the logged-on credentials" need to be set as YES, because if not you are not setting the desktop of the currently logged user. [Image]: https://i.sstatic.net/Wx1d5cZw.png

Also it is more easy to create a configuration profile: create device -> win10 -> Device restrictions profile

There you can change both desktop background and locked screen background:

  • Locked Screen Experience -> Locked screen picture URL
  • Personalization -> Desktop background picture URL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.