I would like to change the desktop wallpaper in Windows (7, if that makes a difference).
My attempt below was not successful. It doesn’t change the wallpaper, registry keys, or do anything other than print ‘0’, as far as I can tell.
require 'Win32API'
SPI_SETDESKWALLPAPER = 20
SPIF_UPDATEINIFILE = 0x1
SPIF_SENDWININICHANGE = 0x2
wallpaper_path = 'C:\\test.bmp'
systemParametersInfo = Win32API.new('user32', 'SystemParametersInfo', ['I','I','P','I'], 'I')
puts systemParametersInfo.call(SPI_SETDESKWALLPAPER, 0, wallpaper_path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
2 hours of googling didn’t get me anywhere. Maybe someone here can help.
My friend figured out that it worked using a different image.
I saved my .bmp file using GIMP, which apparently is problematic if you use the default export options. If I check “Do not write color space information” when exporting, it works fine.
So the code was fine after all.