我使用InstallerClass
编写C#
作为我的安装程序的自定义操作,我可以使用InstallerClass
成功运行外部exe(安装),但是当我尝试在/quiet
中使用InstallerClass
,它不会安装exe。但是我可以在命令提示符下使用/quiet
以静默方式成功安装它。
是否有任何理由或者如何使用C#以无声模式安装?
以下是我在Commit方法中使用的代码(overriden):
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = pathExternalInstaller;
p.StartInfo.Arguments = "/quiet";
p.Start();
答案 0 :(得分:8)
以下是我用来安静地安装和卸载的内容:
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
}
}
答案 1 :(得分:1)
这适合我。
Process process = new Process();
process.StartInfo.FileName = @ "C:\PATH\Setup.exe";
process.StartInfo.Arguments = "/quiet";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();
答案 2 :(得分:0)
您是否尝试过使用安装参数中列出的/Q
或/QB
参数?它可能看起来像这样:
p.StartInfo.Arguments = "/Q";
我从这份文件中得到了这个:http://msdn.microsoft.com/en-us/library/ms144259(v=sql.100).aspx
答案 3 :(得分:0)
这是我为所有用户静默安装应用程序的逻辑:
public void Install(string filePath)
{
try
{
Process process = new Process();
{
process.StartInfo.FileName = filePath;
process.StartInfo.Arguments = " /qb ALLUSERS=1";
process.EnableRaisingEvents = true;
process.Exited += process_Exited;
process.Start();
process.WaitForExit();
}
}
catch (InvalidOperationException iex)
{
Interaction.MsgBox(iex.Message, MsgBoxStyle.OkOnly, MethodBase.GetCurrentMethod().Name);
}
catch (Exception ex)
{
Interaction.MsgBox(ex.Message, MsgBoxStyle.OkOnly, MethodBase.GetCurrentMethod().Name);
}
}
private void process_Exited(object sender, EventArgs e)
{
var myProcess = (Process)sender;
if (myProcess.ExitCode == 0)
// do yours here...
}
答案 4 :(得分:0)
string filePath = @"C:\Temp\Something.msi";
Process.Start(filePath, @"/quiet").WaitForExit();
它对我有用。