"Couldn't set association for project. Check the file is writeable" when trying to generate project files

For anyone is still looking for the solution:

“C:/Program Files/Epic Games/UE_5.1/Engine/Build/BatchFiles/Build.bat” -projectfiles -project=“D:/Unreal Projects/MyProject/MyProject.uproject” -game -rocket -progress