admin管理员组文章数量:1516870
忽略TestHarness.Logger.Log, 这是自定义的写日志的方法, 可以替换成Console.WriteLine()
public static int InvokeMsi(string msiFilePath, string workDir, bool wait, bool uninstall)
{
Process process = null;
string arg = String.Format("/q /{0} \"{1}\"", uninstall ? "x" : "i", msiFilePath);
ProcessStartInfo psi = new ProcessStartInfo("msiexec.exe", arg);
psi.UseShellExecute = false;
if (!String.IsNullOrEmpty(workDir))
{
psi.WorkingDirectory = workDir;
}
else
{
psi.WorkingDirectory = Environment.CurrentDirectory;
}
process = new Process();
process.StartInfo = psi;
try
{
TestHarness.Logger.Log("Starting to {0} using msiexec.exe" + arg, (uninstall ? "uninstall" : "install") + msiFilePath);
process.Start();
}
catch (Exception ex)
{
TestHarness.Logger.Log("Exception: " + ex.Message);
return -1;
}
if (wait)
{
process.WaitForExit();
if (process.ExitCode == 0)
{
TestHarness.Logger.Log("Succeeded! ");
}
return process.ExitCode;
}
else
{
return 0;
}
}
//Install software by using msiexec
public static int InstallMsi(string msiFilePath, string workDir, bool wait)
{
return InvokeMsi(msiFilePath, workDir, wait, false);
}
public static int UninstallMsi(string msiFilePath, string workDir, bool wait)
{
return InvokeMsi(msiFilePath, workDir, wait, true);
}
版权声明:本文标题:用C#与MSIEXEC一招制胜,快速安装Flash内容 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1771141441a3262206.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论