【问题标题】:powershell apply new settings to taskbarpowershell 将新设置应用于任务栏
【发布时间】:2012-10-01 07:49:06
【问题描述】:

我正在使用 powershell 并通过更改注册表项来更改一些任务栏设置。例如我写了一个自动隐藏启用禁用功能。

$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 没有被重新启动。

所以我的问题是:如何在不重新启动 explorer.exe 的情况下将更改应用到 PS 中的任务栏?

【问题讨论】:

    标签: powershell windows-7 explorer taskbar


    【解决方案1】:

    我已经使用上面的脚本向应用程序发送消息,说明注册表中有新设置。并非所有应用程序都可以收到此消息,但我认为 explore 可以。

    试一试,在应用注册表设置后调用它:

    $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()
    

    【讨论】:

    • 这听起来很简单,但是我该如何调用这个函数呢?还有没有办法在没有 c# 参与的情况下在本机 powershell 中做到这一点?
    • 您可以将其保存为Send-HWNDMessage.ps1 在您的$pwd 中,并从powershell 调用它作为`send-HWNDmessage。 P/Invoke 只能通过 add-type 完成。我不知道任何本机命令可以做到这一点。让我知道它是否有效。
    • 它没有。我还发现powershell.com/cs/media/p/8322.aspx,作者声称他可以刷新资源管理器设置,但似乎不适用于自动隐藏。
    • 对不起...尝试等待其他答案。祝你好运。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    相关资源
    最近更新 更多