您是否可以编写Java代码来检查您的本地Internet Explorer';s版本

您是否可以编写Java代码来检查您的本地Internet Explorer';s版本,java,internet-explorer,Java,Internet Explorer,基本上,我只需要编写一个简单的java程序来检测本地安装的Internet Explorer的版本 有javascript代码,但它在浏览器中运行。我想要的是这样的代码: public class VersionTest { public static void main(String[] args) { System.out.println("you IE Version is:" + getIEVersion()); } public static Strin

基本上,我只需要编写一个简单的java程序来检测本地安装的Internet Explorer的版本

有javascript代码,但它在浏览器中运行。我想要的是这样的代码:

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
   }
}

我该怎么做?谢谢

您要查找的注册表项位于:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version

如何读取Java中的注册表项

对于版本,您可以使用
Internet Explorer注册表项。您可以使用类从java执行
Reg Query
。Reg Query是在windows中查询注册表项的命令行工具

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

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);
ArrayList输出=新建ArrayList()
进程p=Runtime.getRuntime().exec(“reg查询\”HKLM\\Software\\Microsoft\\Internet Explorer \“/v版本”);
BufferedReader stdInput=新的BufferedReader(新的InputStreamReader(p.getInputStream()),8*1024);
BufferedReader stdError=新的BufferedReader(新的InputStreamReader(p.getErrorStream()))
字符串s=null;
System.out.println(“这是命令的标准输出:\n”);
而((s=stdInput.readLine())!=null)
输出。添加(s)
字符串internetexplorer_value=(output.get(2));
字符串版本=internet_explorer_value.trim().split(“”[2];
System.out.println(版本);
输出=
9.0.8112.16421

在我的命令提示符下输出
reg query

HKEY\ U本地\计算机\软件\微软\ Internet Explorer

版本REG_SZ 9.0.8112.16421


可能重复@TomaszNurkiewicz:我不同意。这实际上是一个真正的问题。@EdwardThomson我同意,尽管OP需要学习修正原始问题,而不是简单地问一个稍微修改过的版本again@TomaszNurkiewicz:同意。我不知道是同一张海报。对不起,伙计们。我认为一旦问题结束,就无法修改和重新打开。
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;

}