更改了桌面壁纸c#,但之前的壁纸在重启后返回

时间:2018-06-18 08:55:21

标签: c# .net desktop wallpaper

我使用以下代码更改了桌面壁纸:

public sealed class Wallpaper
{

    Wallpaper() { }

    const int SPI_SETDESKWALLPAPER = 20;
    const int SPIF_UPDATEINIFILE = 0x01;
    const int SPIF_SENDWININICHANGE = 0x02;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
    public static void Set(CommandRemoteOsSettings remoteOsSettings)
    {
       CommandRemoteOsSettings;
        List commandsList = remoteOsSettings.getCommandsList();
        RemotoSetBackground cmdSetBackground = (RemotoSetBackground)commandsList.get(0);
        string fit = cmdSetBackground.getFit();
        string aaaa = cmdSetBackground.getImage();
        byte[] bytes = Convert.FromBase64String(cmdSetBackground.getImage());
        System.Drawing.Image image;
        string tempPath = string.Format("{0}\\USC\\temp\\tempbg.bmp", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
        System.IO.FileInfo file = new System.IO.FileInfo(tempPath);
        file.Directory.Create();
        using (MemoryStream ms = new MemoryStream(bytes))
        {
            using (image = Image.FromStream(ms))
            {
                image.Save(tempPath);
            }
        }
        RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
        if (fit.Equals("Stretched"))
        {
            key.SetValue(@"WallpaperStyle", 2.ToString());
            key.SetValue(@"TileWallpaper", 0.ToString());
        }

        else if (fit.Equals("Centered"))
        {
            key.SetValue(@"WallpaperStyle", 1.ToString());
            key.SetValue(@"TileWallpaper", 0.ToString());
        }

        if (fit.Equals("Tiled"))
        {
            key.SetValue(@"WallpaperStyle", 1.ToString());
            key.SetValue(@"TileWallpaper", 1.ToString());
        }
        SystemParametersInfo(SPI_SETDESKWALLPAPER,
         0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);  }
    }
}

问题是,在我重新启动计算机后,桌面壁纸图像会返回到我更改之前的图像。 谢谢!

0 个答案:

没有答案