Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. determine version of microsoft office with java
  2. C:Usersme>assoc .xls
  3. .xls=Excel.Sheet.8
  4.  
  5. C:Usersme>ftype Excel.sheet.8
  6. Excel.sheet.8="C:Program Files (x86)Microsoft OfficeOffice12EXCEL.EXE" /e
  7.        
  8. import java.io.*;
  9. public class ShowOfficeInstalled {
  10.     public static void main(String argv[]) {
  11.       try {
  12.         Process p = Runtime.getRuntime().exec
  13.           (new String [] { "cmd.exe", "/c", "assoc", ".xls"});
  14.         BufferedReader input =
  15.           new BufferedReader
  16.             (new InputStreamReader(p.getInputStream()));
  17.         String extensionType = input.readLine();
  18.         input.close();
  19.         // extract type
  20.         if (extensionType == null) {
  21.           System.out.println("no office installed ?");
  22.           System.exit(1);
  23.         }
  24.         String fileType[] = extensionType.split("=");
  25.  
  26.         p = Runtime.getRuntime().exec
  27.           (new String [] { "cmd.exe", "/c", "ftype", fileType[1]});
  28.         input =
  29.           new BufferedReader
  30.             (new InputStreamReader(p.getInputStream()));
  31.         String fileAssociation = input.readLine();
  32.         // extract path
  33.         String officePath = fileAssociation.split("=")[1];
  34.         System.out.println(officePath);
  35.       }
  36.       catch (Exception err) {
  37.         err.printStackTrace();
  38.       }
  39.     }
  40.   }