As others already reported, the solution with Windows registry is not so convenient because it's needed to logoff or reboot to get effective changes.
I found this C# solution here : https://pimaxplus.com/en/blog/windows/swapping-mouse-buttons/
Immediatly effective, no logoff/reboot required.
Tested and working on Windows 11.
C# code (SwapMouseButtons.cs) :
using System;
using System.Runtime.InteropServices;
class SwapMouseButtons {
[DllImport("user32.dll")]
public static extern Int32 SwapMouseButton(Int32 fSwap);
static void Main(string[] args)
{
// Try to make the right mouse button primary.
int alreadyPrimary = SwapMouseButton(1);
// If the meaning of the mouse buttons was reversed previously,
// before the function was called, the return value is nonzero.
// If the meaning of the mouse buttons was not reversed, the
// return value is zero.
if (alreadyPrimary != 0)
{
// Make the left mouse button primary.
SwapMouseButton(0);
}
}
}
And compile to get an executable file (SwapMouseButtons.exe) :
"%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc" SwapMouseButtons.cs
Then I can call the little .exe from my .bat script.
Happy.