Advertisement
Wasif_Hasan_

Set-WallPaper (Powershell Function)

Sep 10th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Set-Wallpaper {
  2.   [CmdletBinding()]
  3.   Param(
  4.     [Parameter(Mandatory=$True)]
  5.     [ValidateScript({Test-Path $_})]
  6.     [String]$WallpaperPath
  7.   )
  8.   Set-ItemProperty "REGISTRY::HKEY_CURRENT_USER\Control Panel\Desktop" -Name "Wallpaper" -Value "$WallpaperPath"
  9.   taskkill /f /fi "status eq not responding" >$null
  10.   $code = '[DllImport("user32.dll", CharSet = CharSet.Unicode)]'
  11.   $code += "`npublic static extern uint UpdatePerUserSystemParameters();"
  12.   $winApi = Add-Type -MemberDefinition $code -Name WinAPI -Namespace Extern -PassThru
  13.   0..12 | Foreach {$winApi::UpdatePerUserSystemParameters() >$null}
  14.   $open_folders = @()
  15.   $shell = New-Object -ComObject Shell.Application
  16.   $shell.Windows() | Foreach {
  17.     $open_folders += $_.LocationURL
  18.   }
  19.   Stop-Process -Name explorer -Force
  20.   explorer.exe
  21.   $open_folders | foreach {
  22.     explorer $_
  23.   }
  24.   0..12 | Foreach {$winApi::UpdatePerUserSystemParameters() >$null}
  25. }        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement