PowerShell-Desktop Wallpaper based on Resolution Size

We had a new request from our client to apply the desktop wallpaper based on the Resolution of the laptops to ensure that the wallpaper is perfectly maximize on the screen

Please refer on the following steps on how we archive this by using PowerShell Script in Logon Script

  1. We will prepare to copy the files from Central File server to local laptop
  2. Get the Screen Resolution of the laptops
  3. Assign Desktop Wallpaper based on the retrieved Screen Resolution
  4. Refresh the laptop to make the Wallpaper to be applied immediately
#Copy the desktop wallpaper to local laptop 
md c:\AVT\Wallpaper
xcopy \\AVTFS01\AVTWallpaper$\*.* c:\AVT\Wallpaper /Y /D

#Get the screen resolution 
Add-Type -AssemblyName System.Windows.Forms
$Resolution= "{0}x{1}" -f [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width,[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height

#Apply Desktop Wallpaper based on the Screen REsolution 
if ($Resolution = "800x600") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1024x768") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}


if ($Resolution = "768x1280") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop169.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}


if ($Resolution = "900x1440") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop1610.jp"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "960x1280") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1024x1280") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1280x768") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}


if ($Resolution = "1280x960") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1280x1024") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1360x768") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop1610.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1366x768") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop1610.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1600x1200") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop43.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1920x1080") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop1610.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

if ($Resolution = "1920x1200") {

    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\AVT\Wallpaper\AVTDesktop169.jpg"
    rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True
}

#Pause for 5 Seconds and update again the screen 
Start-Sleep -Seconds 5
rundll32.exe user32.dll, UpdatePerUserSystemParameters 2, True

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top