【问题标题】:MSOLEDBSQL Driver installation fails with C#MSOLEDBSQL 驱动程序安装失败并出现 C#
【发布时间】: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


【解决方案1】:

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

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

设置完成后,exe 将安装驱动程序而不会出现问题。

【讨论】:

    猜你喜欢
    • 2022-08-06
    • 2018-05-18
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多