[英]Install SQL Server Silently Using C# Forms Application
我有一個用C#開發的Windows應用程序,我需要將它安裝在只安裝了操作系統和.Net Framework的PC上。 現在,我必須使用此Windows應用程序在該PC上安裝SQL Server 2008 R2 Express版本。 我編寫了安裝/卸載Windows服務的代碼,但是安裝了sql server。 有人可以幫助我做這件事。
請遵循如何在應用程序中嵌入SQL Server Express中的准則。 它涵蓋了您需要的一切 ,包括選擇正確的分發,選擇適當的安裝方法(wpi與setup.exe)以及如何配置安裝。 wiki甚至還有一個關於如何檢測以前的Express安裝的C#代碼,如何從C#調用SQL Express的WPI(Web平台安裝程序):
System.Diagnostics.Process.Start(
@"C:\Program Files\Microsoft\Web Platform Installer\webplatforminstaller.exe",
" /id SQLExpress");
或使用“wpi://”URL處理程序:
System.Diagnostics.Process.Start("wpi://SQLExpress/");
或使用Web App Galery:
System.Diagnostics.Process.Start(
"http://www.microsoft.com/web/gallery/install.aspx?appsxml=&appid=SQLExpress");
最后,使用SQL Express設置(建議用於高級配置):
System.Diagnostics.Process processObj =
System.Diagnostics.Process.Start(@"c:\temp\sqlsetup\setup.exe",
@"/q /Action=Install /Hideconsole /IAcceptSQLServerLicenseTerms=True
/Features=SQL,Tools /InstanceName=SQLExpress
/SQLSYSADMINACCOUNTS=""Builtin\Administrators""
/SQLSVCACCOUNT=""DomainName\UserName"" /SQLSVCPASSWORD=""StrongPassword""");
它有完整的設置參數列表。
您可以使用msiexec.exe 。 您只需通過傳遞MSI路徑即可安裝MSI。 使用命令可以設置是在安裝過程中顯示UI還是將其設置為靜默安裝,
string installCommandString = "/i {0} /qn";
C# code
string installCommandString = "/i {0} /qn";
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.FileName = "msiexec.exe";
startInfo.Arguments = string.Format(installCommandString, "SQL Server MSI Path");
process.Start();
如果您使用的是Visual Studio內置的標准MSI安裝程序,則可以選擇設置先決條件。
在底部附近有一個SQL Server Express選項,您可以指定從供應商或服務器上的某個位置獲取組件的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.