如何强制Windows桌面背景更新或刷新


17

如果我手动更改注册表中的背景图像,如何在不注销的情况下强制其刷新?

我知道bginfo可以做到,但是我想保持简单,不使用任何软件。

Answers:


16
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True

7
这似乎在win7 x64中不起作用...有人对此有帮助吗?
乔恩·克洛斯凯

3
使用它RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True似乎可以在我的机器上正常工作(请注意UpdatePerUserSystemParameters后面缺少的逗号)
星云

可以确认,实际上并没有刷新Win7 x64上的桌面。试图同时调用两个版本的RunDll以防万一。
Okuma.Scott,

3
  • 打开任务管理器
  • 杀死explorer.exe
  • 如果外壳没有立即重启
  • 从菜单中选择文件>新建任务
  • 键入“ explorer.exe”,然后按Enter。

好主意,但这根本解决不了。
Nathan Strutz

2

我试图做类似的事情-更新开始菜单的注册表设置,然后立即让开始菜单反映所做的更改。

这个MSDN问题的解决方案非常适合我。

您可以尝试广播WM_SETTINGCHANGE消息。例如:

class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);

    private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
    private const int WM_SETTINGCHANGE = 0x1a;
    private const int SMTO_ABORTIFHUNG = 0x0002;

    static void Main(string[] args)
    {
        SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
    }
}

1

更改屏幕分辨率,然后选择还原选项。您的分辨率将保持不变,并且背景将发生变化。

或者,断开并重新连接显示电缆。


1
# first in powershell, second both. cmd.exe + powershell.exe

# Refresh Desktop Ability
$definition = @'
    [System.Runtime.InteropServices.DllImport("Shell32.dll")] 
    private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
    public static void Refresh() {
        SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);    
    }
'@
Add-Type -MemberDefinition $definition -Namespace WinAPI -Name Explorer

# Set Safe within deleted days and get physical drive letters
$ignoreDeletedWithinDays = 2
$drives = (gwmi -Class Win32_LogicalDisk | ? {$_.drivetype -eq 3}).deviceid

# Process discovered drives
$drives | % {$drive = $_
    gci -Path ($drive+'\$Recycle.Bin\*\$I*') -Recurse -Force | ? {($_.LastWriteTime -lt [datetime]::Now.AddDays(-$ignoreDeletedWithinDays)) -and ($_.name -like "`$*.*")} | % {

        # Just a few calcs
        $infoFile         = $_
        $originalFile     = gi ($drive+"\`$Recycle.Bin\*\`$R$($infoFile.Name.Substring(2))") -Force
        $originalLocation = [regex]::match([string](gc $infoFile.FullName -Force -Encoding Unicode),($drive+'[^<>:"/|?*]+\.[\w\-_\+]+')).Value
        $deletedDate      = $infoFile.LastWriteTime
        $sid              = $infoFile.FullName.split('\') | ? {$_ -like "S-1-5*"}
        $user             = try{(gpv "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\$($sid)" -Name ProfileImagePath).replace("$(gpv 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList' -Name ProfilesDirectory)\",'')}catch{$Sid}

        #' Various info
        $originalLocation
        $deletedDate
        $user
        $sid
        $infoFile.Fullname
        ((gi $infoFile -force).length / 1mb).ToString('0.00MB')
        $originalFile.fullname
        ((gi $originalFile -force).length / 1mb).ToString('0.00MB')
        ""

        # Blow it all Away
        #ri $InfoFile -Recurse -Force -Confirm:$false -WhatIf
        #ri $OriginalFile -Recurse -Force -Confirm:$false- WhatIf
        # remove comment before two lines above and the '-WhatIf' statement to delete files
    }
}

# Refresh desktop icons
[WinAPI.Explorer]::Refresh()

or 

ie4uinit.exe -ClearIconCache

end scripting enjoy.
#end

1
看起来不错,但是为什么所有驱动器都在那里?
not2qubit

0

接受的答案中的内容对我非常有用。我最终编写了一个while循环,以在后台静默调用代码25次。希望这可以帮助。

来自接受答案的代码:

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True

我的bash脚本顶部的代码:

desktop () {

i=0

# Tell the desktop to refresh 25 times.
while [ $i -le 25 ]
do
  echo "RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters, 1 True"| "C:/Windows/System32/WindowsPowerShell/v1.0/powershell"
  ((i++))
done

}


# This runs the function silently as a background process
desktop &>/dev/null &
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.