我正在写一个 InstallerClass
使用 C#
作为我的安装程序的自定义操作,我可以使用 InstallerClass
成功运行外部 exe(安装) , 但是当我尝试使用 /quiet
在InstallerClass
,它不会安装 exe。但是我可以使用 /quiet
在静默模式下成功安装它在命令提示符下。
这是否有任何原因或如何使用 C# 在静默模式下安装?
以下是我在 Commit 方法(覆盖)中使用的代码:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = pathExternalInstaller;
p.StartInfo.Arguments = "/quiet";
p.Start();
最佳答案
这是我用来进行安静安装和卸载的方法:
public static bool RunInstallMSI(string sMSIPath)
{
try
{
Console.WriteLine("Starting to install application");
Process process = new Process();
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = string.Format(" /qb /i \"{0}\" ALLUSERS=1", sMSIPath);
process.Start();
process.WaitForExit();
Console.WriteLine("Application installed successfully!");
return true; //Return True if process ended successfully
}
catch
{
Console.WriteLine("There was a problem installing the application!");
return false; //Return False if process ended unsuccessfully
}
}
public static bool RunUninstallMSI(string guid)
{
try
{
Console.WriteLine("Starting to uninstall application");
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe", string.Format("/c start /MIN /wait msiexec.exe /x {0} /quiet", guid));
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(startInfo);
process.WaitForExit();
Console.WriteLine("Application uninstalled successfully!");
return true; //Return True if process ended successfully
}
catch
{
Console.WriteLine("There was a problem uninstalling the application!");
return false; //Return False if process ended unsuccessfully
}
}
关于c# - 静默安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7203300/