msiexec 静默安装程序
代码触发安装 静默执行
对于一些不关注安装过程的情况来说,比如软件先通过下载器下载,下载完直接触发安装
private void StartProcess(string filePath, string parameters, Action<string> callback) { try { Process myprocess = new Process(); ProcessStartInfo startInfo; if (!string.IsNullOrEmpty(parameters)) { startInfo = new ProcessStartInfo(filePath, parameters); } else { startInfo = new ProcessStartInfo(filePath); } myprocess.StartInfo = startInfo; myprocess.StartInfo.Verb = "runas"; myprocess.Start(); myprocess.WaitForExit(); callback("程序安装成功!"); } catch (Exception ex) { callback("程序安装失败,请联系管理员!"); //LogUtil.WriteLog(ex.Message); } }
myprocess.StartInfo = startInfo;
myprocess.StartInfo.Verb = "runas";
myprocess.Start();
myprocess.WaitForExit();
myprocess.WaitForExit();不能忽略,忽略会中断安装运行
string parameter = string.Format(@"/i {0} /quiet /qn /norestart /log c:\install.log", filename); StartProcess(@"msiexec.exe", parameter, tip => { installTip.Text = tip; });
参数中filename是msi文件的安装路径