Here are a few tips, based on my past experience with Windows OS ( Lately have not worked on Windows).
Try following
Delete temp files and retry. Hopefully your issue will be resolved but if it still does n't work then goto registry (we need to be very careful while working with registry), find PostgreSQL there and remove it.
I uninstalled Postgresql and wanted to reinstall it again, unfortunately, this error appeared after I tried many times. I searched for a solution online, but I didn’t make it. For example, run as administrator, or use the command regedit to delete the relevant Postgresql folder. I hope you can help me, thanks a lot.