Why does this Batch file fail to change the wallpaper (Windows 7)

谁说胖子不能爱 提交于 2019-12-11 04:37:14

问题


I have a script that runs (without error) to change the desktop wallpaper. The only problem is that it doesn't change the wallpaper. The registry entry is changed appropriately, so that bits working. Just the reloading is not working.

:: Configure Wallpaper
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\Users\greynolds\AppData\Roaming\APOD Wallpaper\apod_wallpaper1.png"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2
:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

回答1:


UpdatePerUserSystemParameters is a undocumented function AFAIK

ReactOS defines it as: BOOL WINAPI UpdatePerUserSystemParameters(DWORD dwReserved,BOOL Enable)

That function definition means that it is not a function you can call with RunDll32 (You end up passing random parameters to the function)




回答2:


As of this writing (in my experience) setting up HKCU\Control Panel\Desktop more often would not work.

The best solution is to call win32 api function SystemParametersInfoSetWallpaper - it works every time. I found this powershell module/snippet to be quite helpful https://gallery.technet.microsoft.com/scriptcenter/Change-window-borderdesktop-609a6fb2




回答3:


Here how you call this function but better to use documented API:

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1 True


来源:https://stackoverflow.com/questions/5018828/why-does-this-batch-file-fail-to-change-the-wallpaper-windows-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!