可以通過cmd命令行來執行,也可以通過代碼來執行,一般都需要管理員權限運行
代碼
/// <summary>/// 靜默安裝/// </summary>/// <param name="fileName">安裝文件路徑</param>/// <param name="arguments">安裝參數</param>/// <param name="isRunas">是否以管理員權限運行</param>/// <returns></returns>public static void SilentInstall(string fileName, string arguments, bool isRunas = true, bool isCreateNoWindow = false){Process processSetup = new Process();processSetup.StartInfo.FileName = fileName;if (isCreateNoWindow)processSetup.StartInfo.CreateNoWindow = true;processSetup.StartInfo.Arguments = arguments;processSetup.EnableRaisingEvents = true;if (isRunas)processSetup.StartInfo.Verb = "runas";processSetup.Exited += delegate { };processSetup.Start();processSetup.WaitForExit();var exitCode = processSetup.ExitCode;processSetup.Close();}
例子
//軟件安裝
SilentInstall(@"C:\Test.msi", @" /quiet /n");//SQL SERVER安裝
string saPwd = "123";
string arguments = $@"/q /ACTION=Install /FEATURES=""SQLENGINE, REPLICATION, SNAC_SDK"" /INSTANCENAME=""SQLExpress"" /SECURITYMODE=""SQL"" /SAPWD=""{saPwd}"" /IACCEPTSQLSERVERLICENSETERMS /UpdateEnabled=False";
SilentInstall(file, arguments);
卸載程序
SilentInstall("msiexec.exe", $" /quiet /n /uninstall {testProductCode}");
ProductCode為安裝程序的ProductCode屬性值
?
參考
靜默安裝_weixin_30741653的博客-CSDN博客
C#卸載軟件 msiexec安裝參數詳解 - 愛碼網
Installshield之靜默安裝_setup.iss_Blue_sky90的博客-CSDN博客
SQLserver靜默安裝(命令行安裝)_Dan淡淡的心的博客-CSDN博客