# Why wont java execute from c:\Windows\System32?

Until a few days ago, I was able to run java applications from the command line, then something broke. I traced the problem down to being unable to invoke java.exe from c:\Windows\System32. Even if I give the full pathname (c:\windows\system32\java.exe) it still wont execute "'c:\Windows\System32\java.exe' is not recognized as an internal or external command, operable program or batch file.". I tried coping it to a different name in the same directory but it still wouldn't work. Only when I copied to java.exe to a different directory & putting that dir into PATH did I finally get it to work so this is my workaround solution but I would still like to know why it stopped executing from c:\Windows\System32 after months of being happy there!

-
I'm not sure how java.exe got into Windows\System32 in the first place but this wasn't an install question. I want to know why java.exe is executable from any directory except this one. – Its me Feb 1 '13 at 21:02
@Karan The Windows installer for Oracle/Sun java does place a copy of the executable in C:\Windows\System32, at least on my Windows 7 machine. This is in addition to the full install located in C:\Program Files\Java – Darth Android Feb 1 '13 at 21:48
@DarthAndroid: You're right, seems it does place a dummy java.exe in system32. – Karan Feb 1 '13 at 22:59

Your problem may have to do with 64-bit vs 32-bit Java JRE installation. I was having similar problems where I could see

C:\Windows\System32\java.exe


but was unable to run it. I found a thread which hinted that there should be a copy of the file at

C:\Windows\SysWOW64\java.exe


for the 64-bit Java to execute from a 32-bit app.

In my case I know a corporate security patch confounded my installation since it worked then didn't work right after I allowed the patch to run.

-

If you want to execute java form the command line, you should add it to your path. Go to Control Panel -> System -> Advanced System Settings, then go to the Advanced tab and click on Environment Variables. Look for the system variable called PATH, and append ;C:\Path\to\java\bin to it. Now you should be able to run java from cmd.exe.

-
java.exe has always been in my PATH. I can execute java now from the CL because I put the new dir into PATH. However, c:\Windows\System32 is also in my PATH but it wont execute java from that location. why? I tried copying other cmds (with new names) into that dir to see if they exexcute & they work fine. So what's up with c:\Windows\System32\java.exe ? – Its me Feb 4 '13 at 15:27

The java.exe in C:\Windows\system32 is put there because that directory will almost certainly be earlier in your path than most others. That is, it's a way of making sure that this java.exe is found first on your path, no matter what JREs or JDKs you have installed.

What this java.exe does is check your registry to see which real java.exe should be launched, and it launches that to replace itself.

The result is, if you want want to run a specific version of java, and you don't have admin privileges (you can edit your user path but cannot edit the system path) then you need to edit the registry to make your desired version the one that will be chosen by the java.exe in C:\Windows\system32.

Per Oracle's doc for Java 1.6.x: "The installation program for the Microsoft Windows version of the Java SE Runtime Environment uses the registry to record path and version information. The application launcher in the system directory uses the registry settings to obtain the location of the Java SE Runtime Environment they are to use when launching an application."

... and ...

"Two copies of the java.exe executable are installed. One copy is in the bin directory of the JRE. The second copy is placed in either C:\windows\system or C:\winnt\system32, depending on the system. Because of its location in the system directory, this second copy of java.exe can be launched from any directory location without giving the full path to it.

This second copy of the java.exe executable relies on the CurrentVersion registry setting to determine which registry key to use to look up the location of the JRE. For example, if the CurrentVersion registry is set to 1.6, the java.exe executable in the system directory will look at the HKEY_LOCAL_MACHINE\Software\JavaSoft\Java SE Runtime Environment\1.6 key to determine where the JRE is installed."

-