Title: [C#] Wallpaper.cs Author: Erb1tux Pastebin link: http://pastebin.com/ykqbRKpn First Edit: Saturday 13th of September 2014 05:23:27 PM CDT Last Edit: Saturday 13th of September 2014 05:23:27 PM CDT using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks;   namespace Background_Changer {     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 enum Style : int         {             Tiled,             Centered,             Stretched         }           public static void Set(Uri uri, Style style)         {             System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString());               System.Drawing.Image img = System.Drawing.Image.FromStream(s);             string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");             img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp);               RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);             if (style == Style.Stretched)             {                 key.SetValue(@"WallpaperStyle", 2.ToString());                 key.SetValue(@"TileWallpaper", 0.ToString());             }               if (style == Style.Centered)             {                 key.SetValue(@"WallpaperStyle", 1.ToString());                 key.SetValue(@"TileWallpaper", 0.ToString());             }               if (style == Style.Tiled)             {                 key.SetValue(@"WallpaperStyle", 1.ToString());                 key.SetValue(@"TileWallpaper", 1.ToString());             }               SystemParametersInfo(SPI_SETDESKWALLPAPER,                 0,                 tempPath,                 SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);               s.Dispose();             img.Dispose();             key.Dispose();         }         public static string GetCurrentWallpaper()         {             // The current wallpaper path is stored in the registry at HKEY_CURRENT_USER\\Control Panel\\Desktop\\WallPaper               RegistryKey rkWallPaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false);             string WallpaperPath = rkWallPaper.GetValue("WallPaper").ToString();             rkWallPaper.Close();               // Return the current wallpaper path             return WallpaperPath;         }       } }