PowerShell

Set Random Wallpaper using Powershell.

Hi,

We all love wallpapers. I and love them too.

Sometime they reflect our moods too. I have a huge collection of Wallpapers and i love to change my wallpapers in once or twice a week.

In the time of windows XP, i used to have a software which changed my wallpaper daily when i login to the laptop.

To be frank i never used to have a any desktop changer software in my windows7 laptop.

Few days ago i just write a small snippet code to change my wallpaper on daily basis.

How i do that ,

It is simple, Powershell + Registry and that all.

Download Link : http://gallery.technet.microsoft.com/scriptcenter/Set-Random-Wallpaper-Using-e79e4235

Lets do it.

The below variable is storing the path to my Pictures. {you can change it to with yours ,, or you can use Join-Path$env:USERPROFILE  -ChildPath Pictures .}

$myPictureFolder=‘C:\Users\aman.dhally\Pictures\’

Now, i am running Get-ChildItem (dir) on our Picture folder, and using Get-Random cmdlet, i am choosing any single  wallpaper randomly.

$getRandomWallpaper=Get-ChildItem-Recurse$myPictureFolder|where {$_.Extension -eq“.jpg”}  |Get-Random-Count 1

Now we are using Set-ItemProperty to set the select wallpaper to the desktop.

To update the desktop we have to use rundll32.exe and to be frank, until we don’t run the  ”

rundll32.exe user32.dll, UpdatePerUserSystemParameters

” code 3-4 time wallpaper wont change. or we reboot the laptop.

Set-ItemProperty-path‘HKCU:\Control Panel\Desktop\’-name wallpaper -value$getRandomWallpaper.FullName 

rundll32.exe user32.dll, UpdatePerUserSystemParameters

Completer Script

$myPictureFolder=‘C:\Users\AD\Pictures\WallPapers\IronMan’

# $myPictureFolder = Join-Path $env:USERPROFILE  -ChildPath Pictures

$getRandomWallpaper=Get-ChildItem-Recurse$myPictureFolder|where {$_.Extension -eq“.jpg”}  |Get-Random-Count 1

Set-ItemProperty-path‘HKCU:\Control Panel\Desktop\’-name wallpaper -value$getRandomWallpaper.FullName 

rundll32.exe user32.dll, UpdatePerUserSystemParameters  

rundll32.exe user32.dll, UpdatePerUserSystemParameters

rundll32.exe user32.dll, UpdatePerUserSystemParameters

Download Link : http://gallery.technet.microsoft.com/scriptcenter/Set-Random-Wallpaper-Using-e79e4235

Note: I tested this on windows 7 32 bit only.

Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007