I'm trying to write a program that creates a slideshow background for Windows 7 Starter. My current program works perfect in XP and on Windows 7 Starter it does nothing. It creates the temporary file just fine but won't set it to the background. When it's run on Windows 7 Home Premium it gives me a "generic error" when trying to run the command to change the background. Here is the portion of my script that actually sets the background:
private void setBackground()
{
if (Counter >= files.Length)
Counter = 0;
if (File.Exists(files[Counter]))
{
files[Counter] = files[Counter].ToLower();
using (Image img = Image.FromFile(files[Counter]))
{
img.Save(tempPath, ImageFormat.Bmp);
}
try
{
if (SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE) != 0)
{
Counter += 1;
}
else
{
MessageBox.Show("There was an error in setting the wallpaper.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch
{
MessageBox.Show("There was an error in setting the wallpaper.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
And just to clear up any confusion about it, tempPath points to temp.bmp which is created in the windows directory, set programmatically so it will work the same way even with a non-default windows directory. After the defined interval time the file at tempPath is written over with the next file in the array. I'm guessing there is a problem with using SystemParametersInfo in Windows 7 and I realize this may not be possible in Windows 7 Starter but I find it hard to believe, and MSDN says nothing of either of these being true. Needless to say, a Google search has turned nothing up.