import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; public class RegPathAdobe { private static final String REGQUERY_UTIL = "reg query "; private static final String REGSTR_TOKEN = "REG_SZ"; // quand on connait la valeur de la clé // private static final String ADOBE_NAME_CMD = REGQUERY_UTIL + // "\"HKLM\\Software\\Adobe\\Acrobat Reader\\7.0\\Installer\" /v Path"; // dans le cas contraire private static final String ADOBE_NAME_CMD = REGQUERY_UTIL + "\"HKLM\\Software\\Adobe\\Acrobat Reader\\7.0\\InstallPath\""; public static String getAdobePath() { try { Process process = Runtime.getRuntime().exec(ADOBE_NAME_CMD); StreamReader reader = new StreamReader(process.getInputStream()); reader.start(); process.waitFor(); reader.join(); String result = reader.getResult(); int p = result.indexOf(REGSTR_TOKEN); if (p == -1) { return null; } return result.substring(p + REGSTR_TOKEN.length()).trim(); } catch (Exception e) { return null; } } //parser du résultat static class StreamReader extends Thread { private InputStream is; private StringWriter sw; StreamReader(InputStream is) { this.is = is; sw = new StringWriter(); } public void run() { try { int c; while ((c = is.read()) != -1) sw.write(c); } catch (IOException e) { ; } } String getResult() { return sw.toString(); } } public static void main(String s[]) { System.out.println(getAdobePath()); } }
Simple, efficace, parfait. Exactement ce que je cherchais !
Merci pour le partage :)
Merci c'est parfait ,mais je veux avoir la valeur du clé RUNc'est possible?
Se souvenir du profil
Mot de passe oublié ? / Activation de compteCréer un compte
1 874 489 membres 86 nouveaux aujourd'hui 16 152 membres club