Install Java 17 and set the path in the start script
For example:
"C:\Program Files\Java\jdk-17.0.9\bin\javaw.exe" @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.2-40.2.18/win_args.txt
pause
Just replace the word "java" in the script with the Java 17 path (to the javaw.exe)
Make sure the path is correct and keep the quotation marks