1

I am using the following Powershell DSC Configuration to disable the visual effects.

Configuration OSConfig 
{
    param
    (
        [parameter()]
        [string]
        $NodeName = 'localhost'
    )

    # It is best practice to always directly import resources, even if the resource is a built-in resource.
    Import-DscResource -Name Service
    Import-DSCResource -Name WindowsClient
    Import-DscResource -Name Registry
    Import-DscResource -Name WindowsFeature
    Import-DscResource -Name WindowsOptionalFeature

    Node $NodeName
    {
        # The name of this resource block, can be anything you choose, as long as it is of type [String] as indicated by the schema.
        Registry VisualEffects
        {
        Ensure = "Present"

        Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects"

        ValueName = "VisualFXSetting"

        ValueData = "2"

        ValueType = "Dword"

        }
    }

  }

After i run the Start-DSCConfiguration Command i can see that visualfxsetting value has updated to 2. But in the GUI(Under Advance System Properties -> Visual effects) its still showing as "let computer choose what's best for you" and not "adjust for best performance". Any thougts about this?

Harshith R
  • 418
  • 1
  • 11
  • 31
  • I think you can remove your (almost) [same question](https://stackoverflow.com/questions/55037273/dsc-configuration-to-disable-visual-effects) 5 hours ago.. – Theo Mar 07 '19 at 12:15

1 Answers1

3

After setting the new value in the registry, you need to let Windows Explorer know something has changed.

A computer restart will do that, but you may try simply restarting the explorer process:

Stop-Process -ProcessName explorer

Another approach could be using Win32 API like this:

function Refresh-Explorer {
    $code = @'
private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);   //  http://www.pinvoke.net/default.aspx/Constants/HWND.html
private const uint WM_SETTINGCHANGE   = (uint)0x1a;                   //  http://www.pinvoke.net/default.aspx/Constants/WM.html
private const uint SMTO_ABORTIFHUNG   = (uint)0x0002;                 //  http://www.pinvoke.net/default.aspx/Enums/SendMessageTimeoutFlags.html
private const uint SHCNE_ASSOCCHANGED = (uint)0x08000000L;            //  http://www.pinvoke.net/default.aspx/Enums/SHChangeNotifyEventID.html
private const uint SHCNF_FLUSH        = (uint)0x1000;                 //  http://www.pinvoke.net/default.aspx/Enums/SHChangeNotifyFlags.html

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

[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(uint eventId, uint flags, IntPtr item1, IntPtr item2);

public static void Refresh()  {
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
}
'@

    Add-Type -MemberDefinition $code -Namespace Win32Refresh -Name Explorer
    [Win32Refresh.Explorer]::Refresh()
}

# call the above function to tell explorer something has changed
Refresh-Explorer

Hope that helps

Theo
  • 57,719
  • 8
  • 24
  • 41