JavaInfo.dll is a Windows DLL (dynamically linked library) that provides information about whether Java is installed and its properties.
Bill Stewart - bstewart at iname dot com
A Java Development Kit (JDK) or Java Runtime Environment (JRE) is required to run Java applications, but there's not a standard way to detect whether Java is installed and details about it. JavaInfo.dll provides this information. For example, you can use JavaInfo.dll in an installer or a Java application launcher executable to detect if Java is installed.
JavaInfo.dll searches for Java in the following three ways:
-
It checks for the presence of the
JAVA_HOME
,JDK_HOME
, orJRE_HOME
environment variable (in that order). -
if the environment variables noted above are not defined, it searches the registry in the
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft
andHKEY_LOCAL_MACHINE\SOFTWARE\IBM
subkeys. If the registry data is found, it returns theJavaHome
value for the latest version. -
If the above search fails, it searches the registry in the
HKEY_LOCAL_MACHINE\SOFTWARE\Azul Systems\Zulu
subkey. If the registry data is found, it returns theInstallationPath
value for the latest version.
NOTE: On 64-bit platforms, JavaInfo.dll does not search the registry for 32-bit versions of Java if it finds any 64-bit versions in the registry, even if there is a newer 32-bit version installed.
- If the previous searches fail, it searches directories in the
Path
environment variable forjava.exe
. The Java home directory is the parent directory wherejava.exe
is found. For example, ifC:\Program Files\AdoptOpenJDK\JRE11\bin
is in the path (andjava.exe
is found in that directory), the Java home directory isC:\Program Files\AdoptOpenJDK\JRE11
.
If any of the above searches succeeds (in the above order), JavaInfo.dll looks for home\bin\java.exe
(where home is the Java home directory). If the file is found, it retrieves the version information from the java.exe
file.
If JavaInfo.dll is successful at finding the java.exe
and retrieving its version information, then it considers Java to be installed.
If JavaInfo.dll is successful at locating a Java installation, you can use the following paths to find Java binaries (where home is the Java home directory):
- home
\bin\java.exe
- Console-based Java executable - home
\bin\javaw.exe
- GUI-based Java executable - home
\bin\server\jvm.dll
- Java virtual machine DLL (used by web servlet containers such as Apache Tomcat)
The 32-bit (x86) DLL works on both 32-bit and 64-bit versions of Windows. Use the x64 DLL with x64 executables on x64 versions of Windows.
Initial version.
Misread Windows documentation on SearchPathW
API function and allocated potentially insufficient buffer size. Fixed.
-
Changed
IsJava64Bit()
function toIsBinary64Bit()
function. The reason for this change is that it is useful to determine whether a binary (i.e., a.exe
or.dll
file) is 64-bit even when Java is not detected. For example, if theIsJavaInstalled()
function returns 0 but an instance of Java is present, you can use theIsBinary64Bit()
function to determine whether the Java instance is 64-bit if you know its path. An added benefit is that theIsBinary64Bit()
function works on any Windows binary, not just Java binaries. -
Included Inno Setup (https://www.jrsoftware.org/isinfo.php) sample script (
JavaInfo.iss
).
-
Updated license to less restrictive LGPL.
-
Changed search order to use environment variables first.
-
Added registry searches for IBM and Azul JDKs.
This section documents the functions exported by JavaInfo.dll.
The IsBinary64Bit()
function detects whether a Windows binary file is 32-bit or 64-bit.
C/C++:
DWORD IsBinary64Bit(LPWSTR FileName, PDWORD Is64Bit);
Pascal:
function IsBinary64Bit(FileName: pwidechar; Is64Bit: PDWORD): DWORD;
FileName
A unicode string containing the name of a binary file (exe or dll).
Is64Bit
A pointer to a variable that gets set to 1 if the specified binary file is 64-bit, or 0 otherwise. The value of this variable is not defined if the IsBinary64Bit()
function fails.
The IsBinary64Bit()
function returns 0 for success, or non-zero for failure.
The IsJavaInstalled()
function detects whether Java is installed.
C/C++:
DWORD IsJavaInstalled();
Pascal:
function IsJavaInstalled(): DWORD;
The IsJavaInstalled()
function returns zero if no Java installations were detected, or non-zero otherwise.
The GetJavaHome()
function gets the Java home directory.
C/C++:
DWORD GetJavaHome(LPWSTR PathName, DWORD NumChars);
Pascal:
function GetJavaHome(PathName: pwidechar; NumChars: DWORD): DWORD;
PathName
A pointer to a variable that receives a unicode string that contains the Java home directory.
NumChars
Specifies the number of characters needed to store the home directory string, not including the terminating null character. To get the required number of characters needed, call the function twice. In the first call to the function, specify a null pointer for the PathName
parameter and 0
for the NumChars
parameter. The function will return with the number of characters required for the buffer. Allocate the buffer, then call the function a second time to retrieve the string.
The GetJavaHome()
function returns zero if it failed, or non-zero if it succeeded.
The GetJavaVersion()
function gets the version of Java as a string in the following format: a.b.c.d
.
C/C++:
DWORD GetJavaVersion(LPWSTR Version, DWORD NumChars);
Pascal:
function GetJavaVersion(Version: pwidechar; NumChars: DWORD): DWORD;
Version
A pointer to a variable that receives a unicode string that contains the Java version string.
NumChars
Specifies the number of characters needed to store the version number string, not including the terminating null character. To get the required number of characters needed, call the function twice. In the first call to the function, specify a null pointer for the Version
parameter and 0
for the NumChars
parameter. The function will return with the number of characters required for the buffer. Allocate the buffer, then call the function a second time to retrieve the string.
The GetJavaVersion()
function returns zero if it failed, or non-zero if it succeeded.