Thursday, January 6, 2011

PostgreSQL Installation Problem on Windows without WSH

PostgreSQL 8.3 and 8.4 may fail to install on Windows with the following error message: "An error occurred executing the Microsoft VC++ runtime installer". PostgreSQL 9.x may fail with a different message: "Unable to write inside TEMP environment variable path", but the actual reason appears to be the same.

It turns out that the installer requires Windows Script Host to be enabled (there might be other reasons, but this is the problem I have stumbled upon).

Before you start messing with the registry, check if WSH is actually disabled or not. To do that run wscript.exe in the DOS box.
  • If you see a dialog box called "Windows Script Host Settings", WSH is enabled, and your problem with PostgreSQL installation must be related to something else.
  • If you get an error box that says "Windows Script Host access is disabled on this machine. Contact your administrator for details", WSH is disabled, and your problem with PostgreSQL installation may be related to it (or may be not).

Here is how to enable Windows Script Host for the current user (assuming he/she has administrator rights, of course):
  1. Start Registry Editor (Start => Run... => regedit).
  2. In the Registry Editor open HKEY_CURRENT_USER\Software\Microsoft\Windows Script Host\Settings
  3. Make sure you actually are "inside" the Settings "folder".
  4. Right-click anywhere in the right pane of the Registry Editor and select New => DWORD Value and call it "Enabled". Then, double-click it and set the "Value data" field to "1".
  5. Check if WSH is now enabled by running wscript.exe in the DOS box (see above).
  6. If WSH is enabled, try installing PostgreSQL. If not, see below how to enable WSH system-wide.
  7. Once the installation is complete, you can disable WSH by setting the "Enabled" value to "0".

The above may not work if Windows Script Host has been disabled system-wide. Here is how to enable it:
  1. Start Registry Editor (Start => Run... => regedit).
  2. In the Registry Editor open HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Script Host\Settings. Note that it is HKEY_LOCAL_MACHINE this time.
  3. Make sure you actually are "inside" the Settings "folder".
  4. Right-click anywhere in the right pane of the Registry Editor and select New => DWORD Value and call it "Enabled". Then, double-click it and set the "Value data" field to "1".
  5. Check if WSH is now enabled by running wscript.exe in the DOS box (see above).
  6. If WSH is enabled, try installing PostgreSQL. If not, you may be using some third-party script blocker or something (I give up).
  7. Once the installation is complete, you can disable WSH by setting the "Enabled" value to "0".

Again, if Windows Script Host is enabled, and PostgreSQL installation still fails, it must be related to something else that I have not encountered.

The above instructions are for Windows XP. They have been tested with PostgreSQL 8.3., 8.4 and 9.0.

They also have been tested on Windows 7 32-bit, but only PostgreSQL 8.4 has been installed.

The procedure should be similar on other versions of Windows.

I have received several reports about failed installation attempts on Windows 7 64-bit and none from Windows 7 32-bit users (or users of any other versions of Windows for that matter), which makes me suspect that this might be something specific to Windows 7 64-bit. Unfortunately, I do not have access to a machine with 64-bit Windows 7 needed to try to re-create the problem. See UPDATE at the very end of this post.

P.S. It had not occurred to me that WSH may be enabled, but the association between WSH and *.vbs files may be missing. It is indeed a possibility. Thanks to DIego, Rain and anonymous commenters for pointing it out.

P.P.S. If you are planning to use the serverctl.vbs script that comes with the Windows installation of PostgreSQL 8.x, you might want to keep WSH enabled. This script allows you to conveniently start and stop PostgreSQL database server directly from the Windows menu, an option that is not critical, but nice to have, especially if you run PostgreSQL on a laptop and do not really want it to run in the background all the time. On the other hand, you can achieve exactly the same simply by running
NET START postgresql_service_name
and
NET STOP postgresql_service_name
without WSH. So, there is hardly any real need to keep Windows Script Host enabled unless you need it for something else..

UPDATE
On a 64-bit Windows 7 system, when you right-click inside HKEY_CURRENT_USER\Software\Microsoft\Windows Script Host\Settings or HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Script Host\Settings and select New, there are two DWORD Value options: DWORD (32-bit) Value and DWORD (64-bit) Value. Somewhat counterintuitively, DWORD (32-bit) Value is the one you should select.

51 comments:

Anonymous said...

Doesn't work on WIN 7 Pro 64 bits

Nicus said...

It doesn't work for me too (W7-64bit) :(

Ira Portman said...

I have updated the original post. Let me know if it helps.

Nicus said...

OK... "my problem is related to something else", as WSH is on
:(

Thank you anyway

Xavier H. said...

I'm the guy who posted about Win 7 64 bits... I just saw your updated post and i see that my problem is "related to somthing else".

I must say that I updated the temp and tmp path to c:\temp

when I try to install, I see new files in the temp folder, so I guess the installation finds the folder and can write to it...

But still not found the solution...
Regards.

Ira Portman said...

Works like a charm on Win7 32-bit. I have an ugly feeling that this might be something specific to Win7 64-bit. I do not have access to a box with 64-bit Win7 to try to re-create the problem.
I would run the installation, let it fail and carefully examine the Windows error log (that's where I found the WSH problem).
Sorry, guys.

Xavier H. said...

Hello, still not working on my win 7 pro 64bits.
Even if I set full rights to everyone on the temp folder.

I can't even find one solution on the web... could anyone help finding the solution?
Thanks

Jeff said...

We're trying to use cygwin to install postgres 9.0 silently on Win 2008 R2 and we ran into this issue too with the TEMP env var error. WSH was enabled on our systems, so that obviously was not our solution

In the end, we believe it to be an issue with the TEMP environment variable. It's defined in Windows/DOS, but not in the cygwin shell where the postgres installer is launched.

This was fixed in our environment by issuing an "export TEMP=/tmp" (or your other favorite temp directory -- C:\Windows\Temp also worked) in cygwin prior to installing postgres, which gives it a valid TEMP directory to use.

Anonymous said...

"my problem is related to something else", as WSH is on :(
Thank you anyway
Postgre 9.0 in Win XP

Anonymous said...

Hi!
I recently posted the comment related to Postgre 9.0 in Win XP (February 8, 2011 11:21 AM).

Here goes the solution that worked for me:

1) Reading the bitrock_installer.log, I found the following error message:

>> Executing cscript //NoLogo "C:\TEMP\prerun_checks.vbs"
>>Script exit code: 1
>>Script output:
>>Input Error: There is no script engine for file extension ".vbs".

2) I corrected the file association of the *.vbs files and set the OPEN action to
C:\WINDOWS\System32\WScript.exe "//e:vbscript" "%1" %*

thus specifying the script engine.

3) The error messages (related to the TEMP directory) disappeared and Postgres was correctly installed.

Anonymous said...

The problem with Windows 7 64 bit still remain.

Unknown said...

First run: regsvr32 %systemroot%\system32\vbscript.dll

Then download and add to registry:
http://www.winhelponline.com/fileasso/vbsfix_vista.zip

And no more pain =)

Anonymous said...

@DIego thanks, that was the only thing working!

Anonymous said...

@DIego much thanks! It worked like a charm for Win XP 32bit, installed successfully. Again much, much thanks for the solution.

Anonymous said...

Hey Thanks

Wembe Kali said...

I am installing on Windows server R2 64 bit;

postgres version:

postgresql-9.0.3-1-windows_x64

Copy the setup to

C:\Users\Administrator\AppData\Local\Temp\1

Installed successfully

Rain said...

As per above comment the same error may appear if wscript is ENABLED but there's NO engine associated with .vbs files.
To fix this:
- navigate to file %windir%\inf\wsh.inf, right click, select 'Install';
- re-run postgresql installer.

Another way is to run installer with "--install_runtimes 0" option:
postgresql-8.4.8-1-windows.exe --install_runtimes 0

The last one helps with PostgreSQL 8.4.8 on MS Windows 2008 R2 64bit to resolve issue described in post.

khendar said...

Another simple way to fix this if you have WScript enabled but its still not working:

Command Line > Run as Administrator
assoc .vbs = VBSFile
ftype VBSFile = wscript.exe

Anonymous said...

@Dlego, wow that works like an arrow

Anonymous said...

I'm having trouble installing PostGreSql on my computer and I tried everything I'd seen on the comments. Is it even possible to run it on Vista cuz that's what I'm using

Ira Portman said...

Theoretically you should be able to install it on Vista, but I cannot verify that since I don't have (and have never had) a machine with Vista. Sorry!
Another option you might want to look into is to use a PostgreSQL virtual appliance (say, using vmWare or something) unless, of course, you absolutely have to run PostgreSQL on Vista.

Anonymous said...

This comment: "the association between WSH and *.vbs files may be missing" finished with hours of failed installation's workarounds. Thanks a lot!

Edwar Saliba JĂșnior said...

I followed Wembe Kali's steps and the PostgreSQL 9.1.3-1 64 bits's installation worked fine.

Thanks!

Ira Portman said...

Somewhat unorthodox... but... whatever works ;-)

Anonymous said...

Dlego: it works for me too on windows xp. Thanks!

Anonymous said...

Hello, i can't install the 8.3.23v and either the 9.2.4, they show me 2 different errors:

"An error has occurred executing the microsoft vc++ runtime installer" with the 8.3

"prerunscript.command.line.error" in 9.2.4

I'm ussing windows 7 starter 32bits.

any solution?

Ira Portman said...

Hi, Anonymous,
I have installed Postgresql 8.4 on Windows Starter 32-bit myself, so what I wrote in the above post should apply to Windows Starter 32-bit as well.

Whether your specific problems are caused by either Windows Script Host being disabled or *.vbs files not being associated with it I don't know.

I have not installed Postgresql above 9.0 on any 32-bit operating systems (just stopped using them).

Another thing you might want to try is to start a DOS box (cmd.exe) as Administrator and start the Postgresql installer from that DOS box. Just a hunch :-) How to start a DOS box as Administrator see here:
http://1stopit.blogspot.com/2011/10/how-to-start-and-stop-postgresql-on.html

I hope this helps. Good luck!

Anonymous said...

Hi, I asked for help a few days ago, thank you for the answer. I already solved the problem, I had to reinstall my antivirus because it showed me a blank screen when i tried to open it, so I couldnt disable the firewall.

Regards.

Ira Portman said...

I am glad you've solved the problem. It is unlikely that the firewall was the culprit though. I'd rather blame some kind of behavior blocker, which your antivirus may use. Mine screams like crazy every time I install or update anything. However, most antivirus programs with behavior blocking, by default, don't show any error messages and just block things they consider suspicious silently, and then it's a real pain in the butt trying to figure out what caused the failed install.

Michl said...

My problem is solved with running the removal tool from mcAfee http://download.mcafee.com/products/licensed/cust_support_patches/MCPR.exe

Ira Portman said...

Michl,

Posting a download link without actually explaining how to use the utility isn't such a good idea. Some people might just run the utility without uninstalling the McAfee product first and mess up their system.

READ McAfee's how-to FIRST!

How to uninstall or reinstall supported McAfee products using the Consumer Products Removal tool (MCPR)
http://service.mcafee.com/FAQDocument.aspx?id=TS101331

Anonymous said...

East or West DIego is the best.

ONLY YOUR SOLUTION WORKED

HATS OFF TO DIego

ADD ME IN YOUR FRIEND LIST
KUMARBLR1@IN.COM

rjburk said...

Found this forum page which down the page a little tells you to get rid of an old erroneous "(default)" McAfee registry entry and put in another correct value. This works like a charm as I was able to get my PostgreSQl 9.x going on my Windows 7 64-bit.
http://forums.enterprisedb.com/posts/list/3040.page
It's pretty easy to fix the problem, just have to eyeball in on the correct line in the registry and change the permission on that one entry folder and change the words on the (default) value

The EnterpriseDB guys gave me a link to one of their pages, I entered the error msg in their search box which found it.

Unknown said...

Enabling WSH worked for me on Windows 8. Thank you.

Ira Portman said...

You are welcome, Tosin.

Unknown said...

Thanks.Work :)

Ira Portman said...

You are welcome, Carlos. Glad it has worked for you.

Anonymous said...

work for win 8 64 bit. thanks

Ira Portman said...

You are most welcome.

Unknown said...

Thanks a lot

heskey said...

Dude Thank you so much. It worked after change the whs in regedit into 1 from the default is 0.

Ira Portman said...

Glad it helped.

andrew said...

The updated solution fixed the issue: "Unable to write inside temp environment variable path".
Im using Win 7 64 bit, DWORD 64 does not exist in the Windows Script Host/Settings instead you can use QWORD 64 and call it Enabled. That fixed the issue for me.

Unknown said...

This worked for me - win 7 64 bit machine:

Looking at thi file located in
C:\Users\{user}\AppData\Local\Temp\bitrock_installer_7392.log
found the log message "Script output:
CScript Error: Windows Script Host access is disabled on this machine. Contact your administrator for details."

Then i
Enable Windows Script Host access using command-line

REG DELETE "HKCU\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled /f

hope it helps

Anonymous said...

Thanks.I could install postgres in my PC after this process.

Ira Portman said...

You are welcome, Ruvinda.

Unknown said...

Thanks that was awesome worked out pretty well

Unknown said...

Thanks Bro!!

Anonymous said...

thanks it really worked

Anonymous said...

Thanks

Unknown said...

I had the same problem with the installation of postgressql
Surprisingly the fix was just to allow Windows-Script on my Antivirus

Now it works perfectly