2017-04-03 117 views
0

你好,我是想做一个小脚本来改变我的壁纸每一个给定的时间 我有哪些图片是名字1.bmp文件夹,2.bmp等更改壁纸的PowerShell

我做了这个脚本但它并没有在所有

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 
>> } 

工作有人可以解释为什么请:(

PS:启动睡眠值是完全随机的,在这里测试

+1

你得到任何错误?如果是这样,他们是什么?如果不是,你看到发生了什么(或没有发生)?如果您希望帮助解决脚本故障,您需要提供尽可能多的信息。请参阅[如何提出一个好问题](http://stackoverflow.com/help/how-to-ask) –

+0

此外,你可能会发现[The Agreeable Cow的这个网页](http://www.theagreeablecow。 com/2014/09/set-desktop-wallpaper-using-powershell.html)。 –

+0

我没有任何错误消息,只有“操作成功”每10次,但我的壁纸不变 –

回答

1

这应该可以解决这个问题(在Win 10中检查):

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 

,或者您可以使用Win32 API的是这样的:

$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")