本文介绍了更改壁纸powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试制作一个小脚本来每次给定时间更改我的墙纸我有一个文件夹,其中图片的名称为 1.bmp 、 2.bmp 等

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

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 : start-sleep 值是完全随机的,这里用于测试

PS : the start-sleep values are totally random and here for testing

推荐答案

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

This should fix the problem(checked in 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:

or you can use win32 api like this:

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

这篇关于更改壁纸powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:08