I decided to try a different method of acheiving the goal. I used Win32::TieRegistry and Win32::GUITest to do it.
It still needs to have some file checks done to see if the input is a valid desktop wallpaper but I'll leave that as an exercise for someone else. I've had way too much fun today!
#!/usr/bin/perl
use strict;
use warnings;
use Win32::TieRegistry;
use Win32::GuiTest qw(FindWindowLike SetForegroundWindow PushButton);
# Is Active Desktop enabled? Get the (REG_BINARY) value from the regis
+try
my $AD = $Registry->{'CUser\Software\Microsoft\Windows\CurrentVersion\
+Explorer\ShellState'};
$AD = unpack("x4 C", $AD ); # A BIG thanks to tye for this line!
if ($AD == 19 or $AD == 99) {
print "Active Desktop enabled.\n";
} elsif ($AD == 35 or $AD == 83) {
print "Active Desktop disabled. Only bitmaps will work.\n";
} else {
die "Unknown registry value";
}
my $input;
if (@ARGV == 0) {
print "Enter the full name of the image to use: ";
$input = <STDIN>;
chomp($input);
exit if ($input eq "");
} else {
$input = $ARGV[0];
}
print "\nUsing $input\n";
# add file tests to see if the input is a valid desktop wallpaper
$Registry->{'CUser\Control Panel\Desktop\WallPaper'} = $input;
system("control","desk.cpl") or die "oopsie";
my @windows = FindWindowLike(0, "^Display Properties"); # find all win
+dows that match
die "oopsie" unless @windows;
my $hwnd = $windows[0]; # we'll just the first match
SetForegroundWindow($hwnd); # Bring it the foreground
PushButton("OK");