【发布时间】:2021-12-03 20:30:23
【问题描述】:
我需要以编程方式安装 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, @"System32\msiexec.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。当我查看事件查看器日志时,我看到一个错误提示缺少 IACCEPTSQLSERVERLICENSETERMS=YES 参数。我尝试在 startInfo 变量中添加参数,如下所示:
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32\msiexec.exe"), $"/i {msiPath} /quiet /IAcceptMSOLEDBSQLLicenseTerms/qn /norestart ALLUSERS=1");
但这不起作用,我得到 1639 错误代码,表示此参数无效。
谁能告诉我如何在我的 startInfo 变量中包含这个参数?
【问题讨论】:
-
我可能已经完全关闭了,但您不需要在字符串中添加 =YES 吗?
-
哎呀!做到了。谢谢@LaurentGabiot :)
-
好,现在你可以写答案了!
标签: c# windows-installer oledb