1

此 vbs 在 XP 上运行良好,但在 Windows 7 下有问题,除非您再次登录,否则壁纸更改不会生效。有没有办法立即重绘桌面?谢谢

设置 w = WScript.CreateObject("Wscript.Shell")
filePath = "D:\wp.bmp"
w.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", filePath
w.Run "%windir%\System32\RUNDLL32. EXE user32.dll, UpdatePerUserSystemParameters", 1, True

4

1 回答 1

4

谢谢你们,正如你们所说,Powershell pInvoke 方法确实是我在网上能找到的唯一可行的解​​决方案,所以我在这里复制它,以防有人遇到同样的问题。

Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
   public class Setter {
      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 );
         RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
         key.Close();
      }
   }
}
"@

[Wallpaper.Setter]::SetWallpaper('D:\wp1.bmp')
于 2013-11-01T18:21:51.633 回答