Powershell将新设置应用于任务栏 [英] powershell apply new settings to taskbar
问题描述
我正在使用Powershell,并且正在通过更改注册表项来更改某些任务栏设置.例如,我编写了一个自动隐藏启用禁用功能.
I am playing around with powershell and am changing some taskbar settings by changing the registry key. For example i have written an autohide enable disable function.
$autoHideSettingsPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2";
$autoHideValueName = "Settings";
Function toggleAutohideRegistrySettings($enable)
{
$key = Get-ItemProperty -Path $autoHideSettingsPath -Name $autoHideValueName;
Write-Host "key is: " + $key
if($enable)
{
$key.$autoHIdeValueName[8] = $key.$autoHideValueName[8] -bor 1;
}else{
$key.$autoHIdeValueName[8] = $key.$autoHideValueName[8] -band 0;
}
Set-ItemProperty -Path $autoHideSettingsPath -Name $autoHideValueName -Value $key.$autoHideValueName;
}
注册表中的更改非常有效.但是要生效,我需要重新启动explorer.exe.我显然也可以在PS中做到这一点...但是我注意到,当您在菜单中(鼠标方式)应用自动隐藏设置时,explorer.exe不会重新启动.
The change in registry works perfectly. But to take effect i need to restart the explorer.exe. Which i can obviously also do in PS... but i noticed that when you apply the autohide settings in the menue (the mouse way), the explorer.exe is not being restarted.
所以我的问题是:如何在不重新启动explorer.exe的情况下将更改应用于PS中的任务栏?
So my question is: how do i apply the changes to the taskbar in the PS, without restarting the explorer.exe?
推荐答案
我已使用上面的脚本向应用程序发送消息,指出注册表中有新设置.并非所有的应用程序都可以收到此消息,但我认为Explore可以.
I've used the script above to send message to applications that there are new settings from the registry. Not all application can receive this message but I think explore does.
尝试一下,在应用注册表设置后调用它:
Give it a try, calling it after registry settings are applied:
$sign = @"
using System;
using System.Runtime.InteropServices;
public static class RegUpdate
{
private const int HWND_BROADCAST = 0xffff;
private const int WM_WININICHANGE = 0x001a, WM_SETTINGCHANGE = WM_WININICHANGE, INI_INTL = 1;
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint wMsg, uint wParam, uint lParam);
public static string SendM()
{
try
{
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, INI_INTL);
return "0";
}
catch (Exception ex)
{
return (ex.Message);
}
}
}
"@
$type = Add-Type -TypeDefinition $sign -Language CSharp -PassThru
$type::SendM()
这篇关于Powershell将新设置应用于任务栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!