我可能会更改 Windows 10 的个性化设置, 例如背景照片,
通过使用 RegEdit 手动更改正确的注册表项或使用具有正确参数的 Powershell 命令“New-ItemPropery”更改正确的注册表项。 我的经验:注册表中的新个性化设置——我可以使用 RegEdit 检查是否所有设置都已正确更改——在下次 Windows 重新启动或 Windows 用户注销+登录后才处于事件状态。 顺便说一句,我正在使用免费工具“WhatChanged”来检测个性化设置中简单更改后的注册表更改。 因此,目前我能够以 Windows 注销+登录的价格更改背景图像。
但是,如果我对 Windows 10 的图形配置工具执行相同操作,通过在鼠标右键单击后选择“个性化”来执行,个性化设置中的更改会立即生效,即背景图片会立即更改。
问题:
是否有免费工具或更好的 PowerShell 功能(调用)或任何其他免费解决方案,通过它我可以立即激活 Windows 个性化(和 Windows 桌面)设置的更改?
我使用的是 Windows10,当然也欢迎适用于 Win95、Win98、W2k、WInXP、WIn7 的解决方案...
原因: 为了提高开发速度,我希望在更改注册表时立即“看到”,即 Windows 个性化,但通常也适用于第三方软件。
根据我的经验,对于其他第三方软件来说,如果在程序启动时只读取一次注册表设置,注册表更改将在软件重新启动后激活,这是很正常的。但即便如此,我也不能为此执行 Windows 注销 + 登录...
真诚的 罗尔夫
最佳答案
要应用桌面更改,您需要调用 Win32 API SystemParametersInfo
来自 user32.dll。
虽然您不能直接从 PowerShell 调用 native Win32 API,但您可以通过 System.Runtime.InteropServices
从 C# 调用它,并且可以将 C# 程序集导入 PowerShell。以下 PowerShell 代码创建一个 C# 程序集来调用 SystemParametersInfo
。
Add-Type @"
namespace Wallpaper {
public class Setter {
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaperFile ( string path ) {
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
}
}
}
"@
function Set-Wallpaper {
param([Parameter(Mandatory=$true)]$Path)
[Wallpaper.Setter]::SetWallpaperFile( $Path )
}
如果您需要更改显示样式,请在调用 SetWallpaperFile
之前更新相应的注册表项。例如,将墙纸样式设置为“居中”:
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name 'WallpaperStyle' -Value '1'
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name 'TileWallpaper' -Value '0'
更改桌面墙纸以外的设置可以类似地完成。请参阅 SystemParametersInfo
的文档。
代码最初改编自 http://poshcode.org/491
关于PowerShell 的 Windows 10 : How to make new Personalisation settings active immediately,?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39495651/