Detect the installed Office version Tag(s): Environment

One way is to call the Windows ASSOC and FTYPE commands, capture the output and parse it to determine the Office version installed.

From the DOS shell :

C:\Users\me>assoc .xls

C:\Users\me>ftype Excel.sheet.8
Excel.sheet.8="C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" /e
From Java code :
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();
        // extract type
        if (extensionType == null) {
          System.out.println("no office installed ?");
        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];
        // output if office is installed :
        //  "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" /e
        // the next step is to parse the pathname but this is left as an exercise :-)
      catch (Exception err) {

blog comments powered by Disqus