Created
April 9, 2019 19:08
-
-
Save dallinbeutler/ba8206ac5c9eb9ef5775f82e395c6a34 to your computer and use it in GitHub Desktop.
Bypass IT enforced wallpaper to your own
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 MyWallpaper | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string path = @"path/to/wallpaper"; | |
Wallpaper.Set(new Uri(path), Wallpaper.Style.Stretched); | |
//RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true); | |
//if (myKey != null) | |
//{ | |
// myKey.SetValue("Wallpaper", path, RegistryValueKind.String); | |
// myKey.Close(); | |
//} | |
} | |
} | |
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment