How to reinstall PostgreSQL over an existing installation
Actually I've found out the problem. At least at my end with the same error.

I was creating an installer for my software with NSIS and it uses the postgresql database, in order to use the postgresql silent install I previously installed it on the target machine to test which parameters I should use, after tested it successfully I then uninstalled it so it could be installed by my software.

Then problem appears when I run my installer and the same error shows:


  The installation directory must be an absolute path, containing only letters, numbers and the characters '-', '/', '.' and '_', and must be writable.


I start to test everything from users, to user permissions, folder permissions, length of folder names.

Then I went to windows registry and found out the my first installation of postgresql left some registries for it even though I uninstalled it from the control panel also it left the postgres user on the machine. 

So I delete all postgresql (Edit->find->postgresql) entries from the registry and also deleted the Windows user (postgres) and then everithing works great.

The only problem now is how to do it through the NSIS program.

Hope it helps.