Windows 10 – How to Force Refresh of Desktop Wallpaper (without logoff/logon)

Hello World, 

This post is investigating the possibility to refresh a desktop wallpaper without the need of a logoff/logon operation. 

The idea of this post comes from a real case scenario.  We have been asked by a customer to find a way to quickly update the Desktop Wallpaper.  This customer decided to use Desktop wallpaper as communication medium in order to distribute information, recommendations or instructions to be followed during COVID-19 Crisis while working at company premises.   

The Desktop Wallpaper was centrally managed and distributed to users through group policies.  The customer wanted to update on regular base the wallpaper in order to communicate critical information and guidance to their users.  However, this specific customer discovered that as long as a user wouldn’t perform a logoff/logon operation, the desktop wallpaper wouldn’t be updated and will not show the latest desktop image distributed via Group Policies through the network.  

This post will quickly explain how to visualize the newly deployed desktop wallpaper without the need of logging off and login on…

Let’s investigate then ….

Overview

Our scenario

As mentioned earlier, our customer was basically using Group policies to centrally manage and deploy Desktop Wallpaper on corporate workstations and laptops.  With the COVID-19 Crisis, new desktop wallpaper needed to be distributed and displayed on the user’s desktop.  Updating the Desktop Wallpaper was a quick and efficient way for that customer to share important information and guidance through the organization.  A user would not need to open his mailbox to know about new policies to be followed. 

The IT Team was using a dedicated group policy to set,manage and deploy the Desktop wallpaper.  The following screenshots shows the really basic settings that needs to be configured at GPO level in order to set desktop wallpapers

Click on Picture for Better Resolution

Click on Picture for Better Resolution

This customer decided to deploy a new Desktop wallpaper through the GPO.  The existing GPO was modified accordingly.  After some time, the GPO would be automatically applied to the target users (or machines). It’s possible to force the refresh of a Group policy by issuing the following command 

gpupdate /force

We have run the resultant Set of Policy (rsop.msc) mmc console to ensure that the new GPO (and thus the new file) was effectively applied on the system.  The new GPO was in place. So, customer expectation’s  was that the new selected desktop wallpaper would be displayed on the screen.  However, the new Desktop wallpaper was not showing up even after multiple gpupdate /force command execution. 

In fact, as long as the user does not perform a logoff/logon, the desktop wallpaper would not update. Also, locking/unlocking screen wouldn’t update the wallpaper.   

Possible solutions/workarounds

We had to come up with some options or workarounds in order to meet the customer requirement (i.e. refresh the desktop wallpaper quickly even if user would not logoff/login).  After some research on internet, we have found that it was possible to use a command line that would theoretically refresh the desktop wallpaper

Option 1 – Rundll.exe & UpdatePerUserSystemParameters (inconsistent results)

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True

For us, this command didn’t really work.  More specifically, the command was working inconsistently which make it unusable in this really specific scenario…. 

We had to find another option.  

Option 2 – Powershell Script (always working) 

Again, searching through internet and gathering information about this specific topic, we discovered that it would be possible to use some specific windows dll that could be loaded into a Powershell script.   After gathering information from multiple Internet sources, we came up with the following short Powershell Script. 

We have tested this script manually and we had 100 % success each time the Desktop Wallpaper GPO (and thus image) was modified….. 

#-------------------------------------------------------------------#
# 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)


So, when the GPO to set the wallpaper was updated,after running the “gpupdate /force” command on a target machine, the desktop wallpaper wouldn’t be updated automatically. Executing the above script was basically updating the user settings in the loaded session and the wallpaper was changed accordingly….

Deploying strategy…

So far, we have simply demonstrated that’s technically possible to update a desktop wallpaper without having the user performing an logoff/logon operation.  Now, the next challenge we have been asked to solve was to find a way to trigger the script when the GPO would be modified…. Probably multiple options would exists and we will present some of them hereafter

Option 1 – Immediate Scheduled Task GPO

So, the first option would be to push a immediate schedule tasks through the network using Group Policies preferences so the new desktop wallpaper would be visible to the user quite quickly after you have modified the GPO.  Obvioulsy, you will have to follow the following steps 

  1. Modify the Desktop Wallpaper GPO accordingly
  2. Create or add in the Desktop Wallpaper policy the immediate Task settings
  3. Modify the script to reflect the name of the new wallpaper name and/or location
  4. Execute a Force gpupdate on all the connected computers (if implemented on your network) or wait for background refresh

We can now create our Immediate Scheduled task GPP. To do that, edit the GPO that will be used to deploy the task, go to User Node > Preferences > Control Panel Settings > Scheduled Tasks.

Right-click anywhere on the right pane and select the option Immediate Tasks (at least Windows 7)

Click on Picture for Better Resolution

In the new Immediate tasks dialog box, Provide a name for the task and leave default for the other settings. Move to the action tab

Click on Picture for Better Resolution

Click on new and in the new Action dialog box, provide the correct information

Click on Picture for Better Resolution

  • In the script, type powershell.exe.
  • In the arguments box ,  type -executionPolicy bypass -windowStyle Hidden -command “\\path_to_the_powershell_Script.ps1”

 

In the common tab, leave the default.  Please note that you should not select the option Run in logged-in user’s security context (user Policy Option).  If this option is selected, the GPO will not run and will throw an error in event viewer. 

Click on Picture for Better Resolution

When the gpo is created, it’s time to push it through your networks.  So, you can force a gpupdate centrally or you can wait for background refresh of the policies and the desktop wallpaper would be updated quite quickly without the need of a logoff/login operation.

Option 2 – Login script or startup folder or scheduled task, create a windows service

Now, another option would be to modify again the script in order to have it running on a specific interval in an infinite loop and distributed to the target machines.  You can use a login script that would execute the script indefinitely. When a new Desktop wallpaper is deployed and when the gpo is refreshed, the script will kick in and update the wallpaper within the user session.  You can also copy shortcuts, batch file in the startup folder on the target machine.  The script would have been modified accordingly to have it running on a infinite loop.  Obviously, with the Startup Folder approach,  all the users needs to perform at least on logoff and logon first in order for the script to be executed and start as a background job !

Click on Picture for Better Resolution

You have multiple options obviously.  You can again create a scheduled tasks that would run at logon or at specific time in order to have the script kicking it on regular base so if a desktop wallpaper would change, this would be reflected quite quickly on users desktop… Another option might be to convert the script into a proper windows service and have it deployed through the organization.  Same principle here : the service would get triggered on a regular base in order to update the user preferences in the current session.  if a new wallpaper would be deployed, the service would kick in and refresh the desktop…

Final Notes

This is it for this post ! 

As demonstrated, it’s possible to force a desktop wallpaper refresh while users are still logged on and when desktop wallpaper are centrally managed by Group Policies.  The process is not complicated but it’s not as straight forward as we would think initially.  The problem is that when the new desktop wallpaper image is distributed through Group policies to computers, the new image will not be displayed on computers where users are currently logged-on (even if a gpupdate /force command has been executed)

Using a Powershell script, we found out that it’s technically possible to refresh desktop wallpapers.  A logged on user executing the script would see immediately the new desktop wallpaper.  The most challenging part is to find a way to automate the execution of the script.  Multiple options exists such as scheduled tasks, login scripts, startup folder, windows service…. You have to choose the best option that would work for you….

Hope you enjoyed this post

Till next time

See ya

 

 

 

 

 

10 thoughts on “Windows 10 – How to Force Refresh of Desktop Wallpaper (without logoff/logon)

  1. Thank you very much for sharing the Powershell script mentioned in Option 2.
    It helped my very well in getting a 20 years old small desktop calendar tool back to life on Windows 10.
    Before I fiddled around with “Rundll.exe & UpdatePerUserSystemParameters” which you you mentioned in Option 1, trying all kinds of switches and parameters, without getting it to work consistently.

    Keep up the good work and keep sharing your insights.

    best regards

  2. @SPB,

    Thank you for visiting our blog and providing your feedback…. Indeed, we had the same issue/feeling and the script was the way to go for us

    Till next time
    See ya

  3. Thanks so much! What I needed to wrap my head around was the changing of the Filename.
    I now understood that I need to have one background image set in the GPO and I can delete the original file and rename the current user-background in Explorer or via automation. Otherwise I would only get a black color background, if these criteria were not met. So to sum it up, there is only one background image and it keeps getting changed in content by the user.

  4. @Horst;
    Thank you for visiting our blog and provide us feedback…We happy to see that information provided has helped you
    Till next time
    See ya

  5. @SerjIQ,

    Thank you for visiting our blog and providing feedback. We are happy to see that this post has been helpful to you and possibly to more people out there…

    Till next time
    See ya

  6. @Jorge;

    Thank you for visiting our blog and providing feedback… sorry for the delay in responding to your message.
    To answer your question, we will need to lookup the documentation, you can probably define additional parameter in the function that would offer you multiple options such as centering picture, stretch picture, tile picture
    Give us a few days (maybe more 🙂 ) and we will try to find out the additional parameters

    Till next time
    See ya

  7. Very helpful thank you, Set this up to download a file from imgur and use that, simple and effective.

  8. @Cai,

    Thank you for visiting our blog and providing feedback. We are always happy to see that some of our posts can be useful and are working as expected

    Till next time
    See ya

Leave a Reply