Set wallpaper for Windows using Ruby

I would like to change the desktop wallpaper in Windows (7, if that matters).

My attempt below was unsuccessful. As far as I know, it does not change the wallpaper, registry keys or anything other than printing '0'.

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 the search robot did not deliver me anywhere. Maybe someone here can help.

+4
source share
1 answer

My friend realized that he was working with a different image.

I saved the .bmp file using GIMP, which seems to be problematic if you use the default export options. If during the export I check "Do not record information about color spaces", it works fine.

So the code was fine.

0
source

Source: https://habr.com/ru/post/1445295/


All Articles