Q: How to detect java by cmd, after installing it, without restarting the PC in windows 10 When I install Java, at the end of the installation, it does not detect it on my system:
C:\Windows\system32>where java
INFO: No file could be found for the given patterns.

and
C:\Windows\system32>java -version
"java" is not recognized as an internal or external command,
executable program or batch file.


Only, when I restart the PC, then it does detect it

Question: what command should I use by cmd to detect the presence of java installed (any version), without restarting the PC?
PD: tested on windows 10 pro x64 21h2
Update:
I have modified Carsten.R's solution:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f *jre* >nul 2>&1 & IF %errorlevel% == 0 (echo OK) else (echo FAIL)


A: You can use the following command line to find the file "java.exe"
cd C:\ & dir /s /b java.exe

It assume that Java is installed in C drive. Otherwise, you can change the drive letter in the command.
If you want to iterate over each drive, and stop directly once a result is found, you can use this powershell command :
$(Get-PSDrive -PSProvider 'FileSystem' |%{ gci -Recurse $_.Root |?{$_.Name -eq "Java.exe"} | Select -First 1}).FullName


A: Hi see my batch file below. That works before reboot, it extracts the install path from the registry and adds it to the search path of the current cmd process.

*

*Find the JAVA HOME with req query

*Split REG_SZ req query

*Trim the result

*Add to the process search path

*Use WHERE or JAVA as you like

@echo off
SETLOCAL
for /f "tokens=*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /V JAVA_HOME  ^|findstr /ri "REG_SZ"') do SET RESULT=%%~a
SET "RESULT=%RESULT:* REG_SZ =%"
for /f "tokens=* delims= " %%a in ("%RESULT%") do set TRIMRESULT=%%a
echo ---%TRIMRESULT%---
SET PATH=%PATH%;%TRIMRESULT%

where java
pause
REM ALTERNATIVE REG KEY
REM reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S /f *jdk-*

By the way the newer OpenJDK 17 https://docs.microsoft.com/en-us/java/openjdk/download , works exactly as you would like. No need of fancy stuff.
If you want to test if something is install in windows querying the uninstall reg keys are the right way. It can be usefull for other applications too.
The example is made with the Microsoft package reg keys can vary base on the entry's, but I am sure you can adopt it easily.
Here an example for jre-8u341-windows-x64.exe
@echo off
SETLOCAL
for /f "tokens=*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f *jre*  ^|findstr /ri "REG_SZ"') do SET RESULT=%%~a
echo 1 ---%RESULT%---
pause
SET "RESULT=%RESULT:* REG_SZ =%"
echo 2 ---%RESULT%---
pause
for /f "tokens=* delims= " %%a in ("%RESULT%") do set TRIMRESULT=%%a
echo 3 ---%TRIMRESULT%---
pause
SET PATH=%PATH%;%TRIMRESULT%

where java

pause

