2012-01-18 63 views
6

基本上,我只需編寫一個簡單的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 String getIEVersion() 
    { //implementation that goes out and find the version of my locally installed IE 
    } 
} 

我該怎麼做?由於

+1

可能重複[如何檢查Internet Explorer的在Java版本(http://stackoverflow.com/questions/8916924/how-to-檢查互聯網探險家版本在爪哇) – 2012-01-18 21:25:45

+2

@TomaszNurkiewicz:我不同意。這實際上是一個真正的問題。 – 2012-01-18 21:27:19

+1

@EdwardThomson我同意,雖然OP需要學習解決原始問題,而不是簡單地要求稍微修改版本 – 2012-01-18 21:28:58

回答

4

您可以使用Internet Explorer Registry Entry作爲版本。您可以使用Runtime類從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); 

輸出=在我的命令提示符下9.0.8112.16421

輸出的reg query

HKEY_LOCAL_MACHINE \ SOFTWARE \微軟\的Internet Explorer

版本REG_SZ 9.0.8112.16421

2
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; 

} 

Source

+1

謝謝你的代碼 – 2013-06-07 21:04:36

相關問題