Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set wallpaper from Windows command prompt on Windows 10?

Tags:

cmd

I've been trying to set my wallpaper in Windows 10 by doing the following in a command prompt window:

reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d wallpaper_directory /f

RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters

This works once, but then if I try to change the wallpaper soon after it, it does not work.

Am I doing something wrong or how do I fix this?

like image 325
Logan Davenport Avatar asked Oct 30 '22 00:10

Logan Davenport


2 Answers

It is very simple go to C:\Users\yourname\AppData\Roaming\Microsoft\Windows\Themes here you find one image with name TranscodedWallpaper. Rename your image to TranscodedWallpaper and replace in this location(don't keep extension). Do same thing inside cachedFile folder also. After exicute RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True then your wallpaped got change

like image 176
Mani Kumar Avatar answered Jan 02 '23 19:01

Mani Kumar


Apparently, "RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters" (with or without "1, True" or "2, True") leads to inconsistent results (at least on my PC). I found the following PowerShell script, that always works on my PC: https://c-nergy.be/blog/?p=15291, option 2:

#-------------------------------------------------------------------#
# ScriptName : SetWall.ps1                                          #
# Description : Force a Desktop wallpaper Refresh                   #
# Credits  : Unknown (if you know original creator, let us know)    #
#                                                                   #
# Date : 01 July 2020                                               #
#-------------------------------------------------------------------#

#Modify Path to the picture accordingly to reflect your infrastructure
$imgPath="\\Domain.lab\netlogon\Wallpaper.png"
$code = @' 
using System.Runtime.InteropServices; 
namespace Win32{ 
    
     public class Wallpaper{ 
        [DllImport("user32.dll", CharSet=CharSet.Auto)] 
         static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ; 
         
         public static void SetWallpaper(string thePath){ 
            SystemParametersInfo(20,0,thePath,3); 
         }
    }
 } 
'@

add-type $code 

#Apply the Change on the system 
[Win32.Wallpaper]::SetWallpaper($imgPath)
like image 23
Stijn Bousard Avatar answered Jan 02 '23 19:01

Stijn Bousard