I have a script.bat
which looks like this:
c:\windows\system32\java.exe -version
pause
If I run the script from a command window, it works fine, and outputs the Java version information:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
However, I also have a VBA macro in Excel that calls the same script:
Shell "C:\users\Matt\script.bat", vbNormalFocus
The .bat
file executes, but it has a problem finding Java:
C:\Users\Matt\Documents>c:\windows\system32\java.exe -version
'c:\windows\system32\java.exe' is not recognized as an internal or external command,
operable program or batch file.
Any ideas on what's going wrong? Oddly, this works fine on a number of other machines, just fails on this one laptop (64-bit Windows 7, using Excel 2010).
It seems to be the same problem as described here:
http://betterlogic.com/roger/2011/04/cannotunable-to-run-java-exe-from-cwindowssystem32/
Namely, Windows was trying to do some 64-bit compatibility magic to redirect C:\Windows\System32\java.exe
to C:\Windows\SysWOW64\java.exe
, but Java didn't install a suitable exe in that location.