
Untitled
By: a guest on
Jun 14th, 2012 | syntax:
None | size: 1.26 KB | hits: 21 | expires: Never
determine version of microsoft office with java
C:Usersme>assoc .xls
.xls=Excel.Sheet.8
C:Usersme>ftype Excel.sheet.8
Excel.sheet.8="C:Program Files (x86)Microsoft OfficeOffice12EXCEL.EXE" /e
import java.io.*;
public class ShowOfficeInstalled {
public static void main(String argv[]) {
try {
Process p = Runtime.getRuntime().exec
(new String [] { "cmd.exe", "/c", "assoc", ".xls"});
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String extensionType = input.readLine();
input.close();
// extract type
if (extensionType == null) {
System.out.println("no office installed ?");
System.exit(1);
}
String fileType[] = extensionType.split("=");
p = Runtime.getRuntime().exec
(new String [] { "cmd.exe", "/c", "ftype", fileType[1]});
input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String fileAssociation = input.readLine();
// extract path
String officePath = fileAssociation.split("=")[1];
System.out.println(officePath);
}
catch (Exception err) {
err.printStackTrace();
}
}
}