locked
How change the wallpaper/background with a command line ? RRS feed

  • Question

  • Hi people,

    did someone know how change the wallpaper with a command line ?

    thx a lot

    Tuesday, November 9, 2010 11:27 AM

Answers

  • Hi,

     

    I think this can be done with PowerShell. We could create a function to set wallpaper:

     

    Function Set-WallPaper($Value)

    {

     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value

     rundll32.exe user32.dll, UpdatePerUserSystemParameters

    }

     

    Open PowerShell; paste the function above in it to make this function work.

     

    Now, if you want to change some wallpaper, you could type the following text:

     

    Set-WallPaper -value "the path of you wallpaper"

     

    If you are interested, I would like to share the following article with you for your reference:

     

    Hey, Scripting Guy! How Can I Hide My Desktop Wallpaper?

     

    If you need some help on writing this script, you can also post your question to The Official Scripting Guys Forum:

     

    The Official Scripting Guys Forum

     

    Hope this helps. Thanks.

     

    Alex Zhao


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Leon Liu - MS Friday, November 19, 2010 6:02 AM
    Friday, November 12, 2010 9:49 AM
  • Hi Alex, i found 2 other solution.

    the first one is to change the theme. like that (line command)

    rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""YOUPATH to the .theme"""
    
    the second one use a thirdparty freeware how work with command line to just change one wallpaper

    http://www.optimumx.com/downloads.html#SetWallpaper (it it work under Win.7)


    Thank for your Powersheel Solution (damn i need to learn Powershell :D )
    • Marked as answer by Leon Liu - MS Friday, November 19, 2010 6:02 AM
    Monday, November 15, 2010 4:27 PM
  • These answers are right, but didn't work too smoothly for me on a 2008 R2 server. 

    If you just want to change a single image rather that updating the registry, then for a 2008 R2 box you need to replace this file:

    c:\users\<UserName>\AppData\Roaming\Microsoft\Windows\Themes\TrancodedWallpaper.jpg

    and then for some reason I needed to run this command twice:

    rundll32.exe user32.dll, UpdatePerUserSystemParameters

    I was doing this with Powershell to automate a testbox setup after a Clone\Replication job. What to check for though is the users "Themes" folder listed above encase it is named differently or you are using BMP files. if you are using PowerShell then you can find out the path and file name with:

    Get-ItemProperty -path 'HKCU:\Control Panel\Desktop' | Select -Property WallPaper

    Of course Cloud_TS has shown a good PowerShell Function to set that to whatever you want, which could be reshaped to centralise the WallPaper across multiple users or groups of users.

    I was looking for a simple swap and refresh and it was knowing the location and that I needed to run the rundll32.exe twice that was really slowing me down.

    Regards,

    Grae Hunter

    Wednesday, February 8, 2017 12:08 AM

All replies

  • Hi,

     

    I think this can be done with PowerShell. We could create a function to set wallpaper:

     

    Function Set-WallPaper($Value)

    {

     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value

     rundll32.exe user32.dll, UpdatePerUserSystemParameters

    }

     

    Open PowerShell; paste the function above in it to make this function work.

     

    Now, if you want to change some wallpaper, you could type the following text:

     

    Set-WallPaper -value "the path of you wallpaper"

     

    If you are interested, I would like to share the following article with you for your reference:

     

    Hey, Scripting Guy! How Can I Hide My Desktop Wallpaper?

     

    If you need some help on writing this script, you can also post your question to The Official Scripting Guys Forum:

     

    The Official Scripting Guys Forum

     

    Hope this helps. Thanks.

     

    Alex Zhao


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Leon Liu - MS Friday, November 19, 2010 6:02 AM
    Friday, November 12, 2010 9:49 AM
  • Hi Alex, i found 2 other solution.

    the first one is to change the theme. like that (line command)

    rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""YOUPATH to the .theme"""
    
    the second one use a thirdparty freeware how work with command line to just change one wallpaper

    http://www.optimumx.com/downloads.html#SetWallpaper (it it work under Win.7)


    Thank for your Powersheel Solution (damn i need to learn Powershell :D )
    • Marked as answer by Leon Liu - MS Friday, November 19, 2010 6:02 AM
    Monday, November 15, 2010 4:27 PM
  • Alex,

    So I copied your Code, changed the value to a location on the Local C drive and this is exactly how I paste in PowerShell

    Function Set-WallPaper($Value)
    {
     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\desert.jpg"

    rundll32.exe user32.dll, UpdatePerUserSystemParameters
    }

    I get a >> }

    Sorry I am not a powershell person, but occasionaly use it for tasks. Thanks for your Help !!


    Friday, November 9, 2012 9:38 PM
  • It works better if you use a .bmp file. Otherwise, you have to allow Windows to convert your .jpg before it will show.
    Wednesday, March 26, 2014 7:10 PM
  • Thanks, this worked for me.  BTW, you dont' need the quotes.  Powershell is clever enough to know it's text and turns the text purple in the text editor.

    Locked down desktops with policies.  Nightmare when Teamviewer8 decides to make your background black and you can't change it back without script.

    Thursday, July 24, 2014 8:02 AM
  • These answers are right, but didn't work too smoothly for me on a 2008 R2 server. 

    If you just want to change a single image rather that updating the registry, then for a 2008 R2 box you need to replace this file:

    c:\users\<UserName>\AppData\Roaming\Microsoft\Windows\Themes\TrancodedWallpaper.jpg

    and then for some reason I needed to run this command twice:

    rundll32.exe user32.dll, UpdatePerUserSystemParameters

    I was doing this with Powershell to automate a testbox setup after a Clone\Replication job. What to check for though is the users "Themes" folder listed above encase it is named differently or you are using BMP files. if you are using PowerShell then you can find out the path and file name with:

    Get-ItemProperty -path 'HKCU:\Control Panel\Desktop' | Select -Property WallPaper

    Of course Cloud_TS has shown a good PowerShell Function to set that to whatever you want, which could be reshaped to centralise the WallPaper across multiple users or groups of users.

    I was looking for a simple swap and refresh and it was knowing the location and that I needed to run the rundll32.exe twice that was really slowing me down.

    Regards,

    Grae Hunter

    Wednesday, February 8, 2017 12:08 AM
  • Save this as a bat file and run the bat file.

    reg add "HKEY_CURRENT_USER\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f 
    reg add "HKEY_CURRENT_USER\control panel\desktop" /v wallpaper /t REG_SZ /d C:\Users\1509967\Desktop\hi.jpg /f
    reg add "HKEY_CURRENT_USER\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
    RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters 
    pause
    exit


    Replace the "C:\Users\1509967\Desktop\hi.jpg " with your file path. If replaced with BMP files, it will be visible instantly. JPG  files may need some refresh or need to be run multiple times.
    Tested and proved on Windows 7.


    Sunday, September 10, 2017 6:37 AM
  • it works on Windows 10.  THX. Not work via Teamviewer like somebody says ;-)
    Monday, January 15, 2018 1:43 PM
  • I tried this solution.

    Sometimes the wallpaper will change and sometimes it won't.

    Tuesday, January 16, 2018 3:47 PM
  • This batch file solved it for me. It checks if it is before or after 20:00 o'clock. If past - sets night wallpaper if before - sets day wallpaper.
    The problem was it sometimes did work at 1st attempt, sometimes after 5th attempt. So I figured it out that the "dll line" should be repeated at least 5 times - now the code works everytime :D

    Add this batch script to your scheduler (at logon and at 20:01) and you will have automagic wallpaper changer based on the time of the day.

    @echo off
    setlocal enabledelayedexpansion
    set "Wtime=!time:~0,2!" 
    if "!Wtime!" leq "20" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "D:\MEGA\Obrazy\Tapety Desktop\mojave_dynamic\mojave_dynamic_8.jpeg" /f  & goto done
    if "!Wtime!" geq "20" reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "D:\MEGA\Obrazy\Tapety Desktop\mojave_dynamic\mojave_dynamic_15.jpeg" /f & goto done
    :done
    timeout /t 5 >nul
    start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters ,1 ,True
    start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters ,1 ,True
    start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters ,1 ,True
    start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters ,1 ,True
    start "" /b RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters ,1 ,True
    endlocal

    Thursday, June 7, 2018 10:36 AM
  • DennisDaniel,

    You missed a piece of the code from Cloud_TS:

    ____________________________________________________________________________

    Function Set-WallPaper($Value)
    {
     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "c:\desert.jpg"

     rundll32.exe user32.dll, UpdatePerUserSystemParameters
    }

    ____________________________________________________________________________________________________

    It should be:

    _________________________________________________________________________

    Function Set-WallPaper($Value)
    {
     Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "$value"

    rundll32.exe user32.dll, UpdatePerUserSystemParameters
    }

    Set-WallPaper -Value "C:\desert.jpg"

    _________________________________________________________________________

    Hope this helps you out. 


    • Edited by Mike Chace Thursday, July 19, 2018 6:41 PM typo
    • Proposed as answer by maximojo22 Friday, May 31, 2019 1:07 AM
    Thursday, July 19, 2018 6:40 PM
  • Hi,

    in Batch:

    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d  "wallpaper_path" /f
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v WallPaperStyle /t REG_SZ /d  10 /f
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Tilewallpaper /t REG_SZ /d  0 /f
    
    FOR /L %%i IN (1,1,50) DO (
    echo Reload %%i of 50
    start RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
    )

    In CMD Shell:

    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d  "wallpaper_path" /f
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v WallPaperStyle /t REG_SZ /d  10 /f
    reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Tilewallpaper /t REG_SZ /d  0 /f
    
    FOR /L %i IN (1,1,50) DO (RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters)

    Tuesday, July 28, 2020 10:06 PM