MSOLEDBSQL驱动程序安装失败,返回C#



我需要以编程方式安装MSOLEDBSQL驱动程序(msi文件(,为此我编写了以下函数:

public static void InstallSQLDriver()
{

string msiPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+@"msoledbsql.msi";
string winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32msiexec.exe"), $"/i {msiPath} /quiet /qn /norestart ALLUSERS=1");
startInfo.Verb = "runas";
startInfo.UseShellExecute = true;
Process proc = Process.Start(startInfo);
proc.WaitForExit();
Console.WriteLine("process ended with : " + proc.ExitCode);
}

这在开发机器上运行良好,并以状态代码0(成功(退出。但是,当我在另一台机器上运行.exe时,它会给我退出代码1603。当我查看事件查看器日志时,我看到一个错误,说IACCCEPTSQLSERVERLICENSETRMS=YES参数丢失。我尝试在startInfo变量中添加如下参数:

ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32msiexec.exe"), $"/i {msiPath} /quiet /IAcceptMSOLEDBSQLLicenseTerms/qn /norestart ALLUSERS=1");

但这不起作用,我得到了1639错误代码,它说这个参数无效。

有人能告诉我如何在我的startInfo变量中包含这个参数吗?

这个非常简单。IAcceptMSOLEDBSQLLicenseTerms的值需要在startInfo字符串中作为YES传递。因此,新的startInfo变量如下所示:

ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32msiexec.exe"), $"/i {msiPath} /quiet IAcceptMSOLEDBSQLLicenseTerms=YES  /qn ACCEPTEULA=1 /norestart ALLUSERS=1");

设置好后,exe安装驱动程序时不会出现问题。

最新更新