Changing a wallpaper should be a trivial task, shouldn’t it? All we need to do is to replace a file… This post walks you through hurdles you will stumble up and how to get through them.
Default Windows 8.1 wallpaper is stored in C:\windows\web\wallpaper\Windows directory and is called img0.jpg. However, you can’t just overwrite the file out of the box due to permissions – trying to do so will only return “Access denied” message. To get round that we first need to take ownership of the file and then grant Full Control to Administrators group (I am assuming that your Task Sequence is running using admin account). There are two handy commands that can do just that for us:
takeown /f C:\Web\Wallpaper\Windows\img0.jpg icacls "C:\Web\Wallpaper\Windows\img0.jpg" /grant "Administrators":F
Having those permissions changed, we can now safely replace the the file:
xcopy /Q /R /Y custom_wallpaper.jpg C:\Web\Wallpaper\Windows\img0.jpg
In next step we point relevant registry key to our file (out of the box it will already be set to it anyway):
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /d "C:\windows\web\wallpaper\Windows\img0.jpg" /f
And now for the final obstacle. Typically for these changes to take effect, we would need to either log off or use a command to activate HKEY_CURRENT_USER changes. I have found both solutions bit unreliable (hit and miss results) if you don’t purge cached wallpaper first. This can be done by deleting TranscodedImageCache value and refresh settings using one of the methods mentioned above.
reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v TranscodedImageCache /f rundll32.exe user32.dll, UpdatePerUserSystemParameters
This will rebuild the cache using new wallpaper and changes will be applied immediately. So, for completeness our script turns into the following set of commands:
takeown /f C:\Web\Wallpaper\Windows\img0.jpg icacls "C:\Web\Wallpaper\Windows\img0.jpg" /grant "Administrators":F xcopy /Q /R /Y custom_wallpaper.jpg C:\Web\Wallpaper\Windows\img0.jpg reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /d "C:\windows\web\wallpaper\Windows\img0.jpg" /f reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v TranscodedImageCache /f rundll32.exe user32.dll, UpdatePerUserSystemParameters
Ni post, but I have a question…
At which level of the Task Sequence do you insert the script?
Thanks!
LikeLike
Hi Gianluigi, thank you for your comment. I am running this script as part of Custom Tasks (in State Restore phase of the build).
LikeLike