Question:
Hello i’m trying to make a little script to change my wallpaper every given time
i have a folder in which the pictures are name 1.bmp , 2.bmp etc
i made this script but it doesn’t work at all
1 2 3 4 5 6 7 8 |
PS D:\Téléchargements\images\Wallpapers> for($i=1; $i -le 6; $i++){ >> reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d D:\Téléchargements\images\Wallpapers\$i.bmp /f >> Start-Sleep -s 10 >> rundll32.exe user32.dll, UpdatePerUserSystemParameters >> Start-Sleep -s 2 >> } |
can someone explain why please 🙁
PS : the start-sleep values are totally random and here for testing
Answer:
This should fix the problem(checked in win 10):
1 2 3 4 |
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d h:\Quotefancy-1542-3840x2160.jpg /f Start-Sleep -s 10 rundll32.exe user32.dll, UpdatePerUserSystemParameters, 0, $false |
or you can use win32 api like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$setwallpapersrc = @" using System.Runtime.InteropServices; public class wallpaper { public const int SetDesktopWallpaper = 20; public const int UpdateIniFile = 0x01; public const int SendWinIniChange = 0x02; [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); public static void SetWallpaper ( string path ) { SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange ); } }"@ Add-Type -TypeDefinition $setwallpapersrc [wallpaper]::SetWallpaper("h:\Quotefancy-1542-3840x2160.jpg") |