2012-01-18 5 views
6

基本的には、ローカルにインストールされたInternet Explorerのバージョンを検出するための単純なJavaプログラムを作成するだけです。ローカルのInternet Explorerのバージョンを確認するためのJavaコードを書くことができます

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

はどのように私はそれを行うのですか?あなたはJavaでレジストリエントリを読むにはどうすればよい

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version 

:ありがとう

+1

可能複製(http://stackoverflow.com/questions/8916924/how-to- [JavaでInternet Explorerのバージョンを確認する方法] check-internet-explorers-version-in-java) –

+2

@TomaszNurkiewicz:私は同意しません。これは実際には本当の質問です。 –

+1

@エドワードトムソン私は同意しますが、OPはわずかに変更されたバージョンを再度尋ねるのではなく、オリジナルの質問を修正することを学ぶ必要があります。 –

答えて

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

出力=私のコマンドプロンプト上reg query9.0.8112.16421

出力

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

コードをありがとう –

関連する問題