Can you write Java code to check the local version of Internet Explorer

Basically, I just need to write a simple java program to detect the version of the locally installed Internet Explorer.

Here is the javascript code, but it works in your browser. what i want is this code:

public class VersionTest { public static void main(String[] args) { System.out.println("you IE Version is:" + getIEVersion()); } public static String getIEVersion() { //implementation that goes out and find the version of my locally installed IE } } 

How can I do it? Thanks

+6
source share
3 answers

You can use Internet Explorer Registry Entry for version. You can execute Reg Query from java using the Runtime class. Reg Query is a command line tool for querying registry entries in windows.

 Process p = Runtime.getRuntime().exec("reg query \"HKLM\\Software\\Microsoft\\Internet Explorer\" /v Version"); 

Full code:

 ArrayList<String> output = new ArrayList<String>() Process p = Runtime.getRuntime().exec("reg query \"HKLM\\Software\\Microsoft\\Internet Explorer\" /v Version"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()),8*1024); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())) String s = null; System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) output.add(s) String internet_explorer_value = (output.get(2)); String version = internet_explorer_value.trim().split(" ")[2]; System.out.println(version); 

Output = 9.0.8112.16421

Reg Query output on my command line

HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Internet Explorer

Version REG_SZ 9.0.8112.16421

+4
source

The registry entry you are looking for is located at:

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version 

How do you read registry entries in Java? Read this stack overflow question.

+2
source
 private String getBrowserType(String currValue){ String browser = new String(""); String version = new String(""); if(currValue != null ){ if((currValue.indexOf("MSIE") == -1) && (currValue.indexOf("msie") == -1)){ browser = "NS"; int verPos = currValue.indexOf("/"); if(verPos != -1) version = currValue.substring(verPos+1,verPos + 5); } else{ browser = "IE"; String tempStr = currValue.substring(currValue.indexOf("MSIE"),currValue.length()); version = tempStr.substring(4,tempStr.indexOf(";")); } } System.out.println(" now browser type is " + browser +" " + version); return browser + " " + version; } 

A source

+2
source

Source: https://habr.com/ru/post/906343/


All Articles