【问题标题】:rundll32 UpdatePerUserSystemParameters not working with Windows 7rundll32 UpdatePerUserSystemParameters 不适用于 Windows 7
【发布时间】:2016-09-05 15:30:01
【问题描述】:

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

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

【问题讨论】:

  • 在 Windows Vista 中,这种墙纸更改方法不起作用。或者至少不像预期的那样。对注册表的更改将适用于新登录。立即更改壁纸的唯一可靠方法是使用 windows api。你可以得到here你需要的东西

标签: vbscript


【解决方案1】:

谢谢你们,正如你们所说,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-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多