powershell - 更改壁纸powershell

标签 powershell

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

我制作了这个脚本,但它根本不起作用

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

最佳答案

这应该可以解决问题(在 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") 

关于powershell - 更改壁纸powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43187787/

相关文章:

powershell - 带有等待参数的 Get-Content 不会在 Powershell 中更新

azure - 如何获取在 Azure 中使用基本 SKU 的资源列表?

Powershell DSC - 使用 cChocoInstaller installChoco 在首次运行后显示不合规

windows - Powershell glob 模式匹配

powershell - 从许可证阵列中删除重复项

powershell - 连接两个数组?

windows - 在 Powershell 4 中使用 'Get-MsmqQueue' 获取远程 MSMQ 对象

Azure DevOps : while using Release Pipeline in classic mode, 我无法将变量的值传递给其他任务

powershell - 如何使用 -SasToken 而不是 -StorageAccountKey 调用 New-AzureStorageContext

arrays - 在PowerShell中比较两个更大的文本数组