在java中运行.msi文件

时间:2012-08-16 17:17:15

标签: java windows-installer

所以我尝试像运行exe文件一样运行.msi文件,这可能是问题所在。我收到此错误消息

  

java.io.IOException:无法运行程序" \":CreateProcess error = 193,   %1不是有效的Win32应用程序

       try {   Runtime rf = Runtime.getRuntime(); 
                   Process pf = rf.exec("\\IE8fix.msi");    
                } catch(Exception e) {                 
                    System.out.println(e.toString());                 
                            e.printStackTrace();
                                                    } 

2 个答案:

答案 0 :(得分:4)

Windows安装程序位于%windir%\ msiexec.exe中 MSI文件不是独立的。它需要像msiexec \"file.msi\"一样运行 所以使用:

try {
   Runtime rf = Runtime.getRuntime(); 
   Process pf = rf.exec("msiexec /i \"\\IE8fix.msi\"");    
} catch(Exception e) {                 
   //System.out.println(e.toString()); // not necessary       
   e.printStackTrace();
} 

答案 1 :(得分:0)

.msi文件不是像exe这样的独立程序,应该从Windows Installer运行这样的东西(我希望这是正确的):

Process pf = rf.exec("msiexec \"\\IE8fix.msi\"");    
相关问题