Advertisement
Guest User

desktopchange.ps

a guest
Jul 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (new-object System.Net.WebClient).DownloadFile('http://your-website.com/mylittlepony.jpg',"$Env:Temp\\b.jpg");
  2. Add-Type @"
  3. using System;
  4. using System.Runtime.InteropServices;
  5. using Microsoft.Win32;
  6. namespace Wallpaper
  7. {
  8. public enum Style : int
  9. {
  10.    Tile, Center, Stretch, NoChange
  11. }
  12. public class Setter {
  13.  public const int SetDesktopWallpaper = 20;
  14.  public const int UpdateIniFile = 0x01;
  15.  public const int SendWinIniChange = 0x02;
  16.  [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  17.  private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
  18.  public static void SetWallpaper ( string path, Wallpaper.Style style ) {
  19.     SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
  20.     RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\\\Desktop", true);
  21.     switch( style )
  22.     {
  23.        case Style.Stretch :
  24.           key.SetValue(@"WallpaperStyle", "2") ;
  25.           key.SetValue(@"TileWallpaper", "0") ;
  26.           break;
  27.        case Style.Center :
  28.           key.SetValue(@"WallpaperStyle", "1") ;
  29.           key.SetValue(@"TileWallpaper", "0") ;
  30.           break;
  31.        case Style.Tile :
  32.           key.SetValue(@"WallpaperStyle", "1") ;
  33.           key.SetValue(@"TileWallpaper", "1") ;
  34.           break;
  35.        case Style.NoChange :
  36.           break;
  37.    
  38.     key.Close();
  39.      }
  40.    }
  41. }
  42. "@
  43. [Wallpaper.Setter]::SetWallpaper("$Env:Temp\b.jpg" , 2 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement