4

私はpowershellで遊んでいて、レジストリキーを変更してタスクバーの設定を変更しています。たとえば、autohide enable disable 関数を作成しました。

$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 のタスクバーに変更を適用するにはどうすればよいですか?

4

1 に答える 1

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()
于 2012-10-01T08:15:10.567 に答える