I had the below code running daily with no issues. I'm not sure what "refresh" you're referring to, or why you have to play with the registry. I ran this from a scheduled task or by hand and the background would refresh instantly
Usage:
perl wallpaper.pl bg.jpg
wallpaper.pl:
use Win32::API;
use constant SPI_SETDESKWALLPAPER => 20;
use constant SPIF_UPDATEANDSENDINI => 3;
use constant NULL => 0;
my $syspinf = Win32::API->new('user32','SystemParametersInfo', [I,I,P,
+I], I)
or die "Could not import function.\n";
$syspinf->Call(SPI_SETDESKWALLPAPER, 0, $ARGV[0], SPIF_UPDATEANDSENDIN
+I);
This script was part of a larger series of scripts that would pull down RSS data, pull the next 2 days of meetings from outlook, then overlay it at specific coordinates (with GD) on top of my background image...
then I'd run the following where bg.jpg was the dynamically generated image.
Update: As for suppressing the cmd window... my script ran at 5am so I never saw it, but the .bat that the scripts are wrapped in begins with @echo off. Also, I thought there was an option in windows task scheduler to run as "Hidden".