You can use PowerShell! We need to invoke SystemParametersInfo with an appropriately configured ANIMATIONINFO structure, since that Windows API function sends the window message that causes the change to take effect immediately. I wrote this script:
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)] public struct ANIMATIONINFO {
public uint cbSize;
public bool iMinAnimate;
}
public class PInvoke {
[DllImport("user32.dll")] public static extern bool SystemParametersInfoW(uint uiAction, uint uiParam, ref ANIMATIONINFO pvParam, uint fWinIni);
}
"@
$animInfo = New-Object ANIMATIONINFO
$animInfo.cbSize = 8
$animInfo.iMinAnimate = $args[0]
[PInvoke]::SystemParametersInfoW(0x49, 0, [ref]$animInfo, 3)
The C# part defines the structure and function that we need to call. Then the script creates the animation configuration structure, and finally it calls the function. 0x49 is the code that tells SystemParametersInfo to set the animation setting and the 3 in the last parameter specifies that we want both the user profile to be updated and the setting change notification sent.
To use the script, save it as a .ps1 file, e.g. windowanim.ps1. Follow the instructions in the Enabling Scripts section of the PowerShell tag wiki to allow script execution, then you can run this command from a batch file to disable window animations:
powershell -c .\windowanim.ps1 $false
If you want to enable the animations, supply $true to the script instead.
If the function invocation is successful, you'll see True printed to the console, no matter whether you enabled or disabled animations.