AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 79169457
Accepted
nikhil
nikhil
Asked: 2024-11-08 17:29:33 +0800 CST2024-11-08 17:29:33 +0800 CST 2024-11-08 17:29:33 +0800 CST

删除旧包后,Wix 不会安装新的 exe 包

  • 772

我正在尝试卸载 SqlServer 2017 并安装 SqlServer 2022。它正在卸载 SqlServer 2017,但从不安装 2022。请帮忙。

我有一个名为 RemoveSql2017.cs 的类,如下所示:

 public class RemoveSQL2017
    {
        const string UNINSTALL_SQL_2017 = "/Action=Uninstall /INSTANCENAME=PHARMSPEC /FEATURES=SQL /QS /HIDECONSOLE";
        const string sqlFile = "DetachPharmSpecDB.sql";
        const string DB_INSTANCE = "PHARMSPEC";
        const int COMMAND_LINE_WAIT = 10000;
        private static WixBootstrapper _bootstrapper;
        const string registryKey = @"SOFTWARE\HIAC\PharmSpec\Database";
        const string subKeyValue = "DataPath";

        public RemoveSQL2017(WixBootstrapper bootstrapper)
        {
            _bootstrapper = bootstrapper;
        }

        public void Remove(string bootStrapFolder, string dataFilePath)
        {
            CreateDetachSQLFile();
            CopyFiles(dataFilePath);
            UninstallSQL(bootStrapFolder);
            DeleteDBRegistryPath();
        }
        public static void UninstallSQL(string bootstrapFolder)
        {
            try
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Beginning UninstallSQL; bootstrapFolder=" + bootstrapFolder);
                Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo(bootstrapFolder + "//SQL2017//setup.exe", UNINSTALL_SQL_2017);
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Completing UninstallSQL; bootstrapFolder=" + bootstrapFolder);
            }
            catch (Exception e)
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Error in UninstallSQL:\n " + e.ToString());
                throw (e);
            }
        }
        public static void CopyFiles(string dataFilePath)
        {
            try
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Beginning CopyFiles; dataFilePath=" + dataFilePath + "  tempDBFilePath=" + Globals.tempDBFilePath);
                File.Copy(Path.Combine(dataFilePath, Globals.MDF_FILE), Path.Combine(Globals.tempDBFilePath, Globals.MDF_FILE));
                File.Copy(Path.Combine(dataFilePath, Globals.LDF_FILE), Path.Combine(Globals.tempDBFilePath, Globals.LDF_FILE));
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Completing CopyFiles; dataFilePath=" + dataFilePath + "  tempDBFilePath=" + Globals.tempDBFilePath);
            }
            catch (Exception e)
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Error in CopyFiles:\n " + e.ToString());
            }
        }
        public static void DetachDB(string sqlFilePath)
        {
            try
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Beginning DetachDB; sqlFilePath=" + sqlFilePath);
                string command = string.Format("-S .\\{0} -E -i \"{1}\"", DB_INSTANCE, sqlFilePath);
                ProcessStartInfo info = new ProcessStartInfo("sqlcmd", command);
                info.UseShellExecute = false;
                info.CreateNoWindow = false;
                info.WindowStyle = ProcessWindowStyle.Hidden;
                Process proc = new Process();
                proc.StartInfo = info;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.Start();
                string outputD = proc.StandardOutput.ReadToEnd();
                if (proc.WaitForExit(COMMAND_LINE_WAIT))
                {
                    _bootstrapper.Engine.Log(LogLevel.Verbose, outputD);
                }
                else
                {
                    _bootstrapper.Engine.Log(LogLevel.Verbose, "Process timeout in DetachDb");
                }
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Completing DetachDB; sqlFilePath=" + sqlFilePath);
            }
            catch (Exception e)
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "Error in DetachDB:\n " + e.ToString());
                throw (e);
            }
        }
        public static void CreateDetachSQLFile()
        {
            try
            {
                string sqlFilePath = Path.Combine(Path.GetTempPath(), sqlFile);
                var sqlScript = new StringBuilder();
                sqlScript.AppendLine("GO");
                sqlScript.AppendLine("IF EXISTS (SELECT * FROM sysdatabases WHERE name = N'PharmSpecDB')");
                sqlScript.AppendLine("use PharmSpecDB");
                sqlScript.AppendLine("DROP SCHEMA PharmSpecUsr");
                sqlScript.AppendLine("DROP USER PharmSpecUsr");
                sqlScript.AppendLine("use master");
                sqlScript.AppendLine("EXEC sp_detach_db 'PharmSpecDB'");
                sqlScript.AppendLine("GO");
                sqlScript.AppendLine("IF EXISTS (SELECT * FROM syslogins WHERE name = N'PharmSpecUsr')");
                sqlScript.AppendLine("DROP LOGIN PharmSpecUsr");
                sqlScript.AppendLine("GO");
                using (StreamWriter sw = new StreamWriter(sqlFilePath))
                {
                    sw.Write(sqlScript.ToString());
                }
                DetachDB(sqlFilePath);
            }
            catch (Exception e)
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "error in CreateDetachSQLFile:\n " + e.ToString());
                throw (e);
            }
        }

        public static void DeleteDBRegistryPath()
        {
            try
            {
                using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                {
                    RegistryKey subkey = key.OpenSubKey(registryKey, true);
                    if (subkey != null)
                    {
                        subkey.DeleteValue(subKeyValue);
                    }           
                }
            }
            catch (Exception e)
            {
                _bootstrapper.Engine.Log(LogLevel.Verbose, "error in DeleteDBRegistryPath:\n" + e.ToString());
            }
        }

我按如下方式调用此类:我能够看到 SqlServer 2017 被卸载。

 if (Bootstrapper.Engine.StringVariables["PreviousVersion"].CompareTo("3.5.99") <= 0 &&
               Bootstrapper.Engine.StringVariables["SqlInstanceKeyFound64"] == "1")
                {
                    RemoveSQL2017 removeSQL = new RemoveSQL2017(Bootstrapper);
                    removeSQL.Remove(Bootstrapper.Engine.StringVariables["DB2017SETUP"], Bootstrapper.Engine.StringVariables["2017DBDataPath"]);
                    Bootstrapper.Engine.StringVariables["OLDDBDATAPATH"] = Globals.tempDBFilePath;
                    Bootstrapper.Engine.StringVariables["INSTALLSQL"] = "1";
                }

我有一个 SqlServer.wxi,其中的注册表项和 exe 文件如下。在删除 SqlServer2017 之前,注册表中的内容如下,

註冊

sqlserver.wxi

<Variable Name="SqlInstanceKeyFound" Value="0"/>
        <Variable Name="SqlInstanceKeyFound64" Value="0"/>
<util:RegistrySearch
          Id="SqlInstanceKeyFound64"
          Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" Value="PHARMSPEC"
          Result="exists" Variable="SqlInstanceKeyFound64" Win64="yes"/>
        <util:RegistrySearch
          Id="SqlInstanceKey64"
          Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" Value="PHARMSPEC"
          Variable="SqlInstanceKey64" After="SqlInstanceKeyFound64" Condition="SqlInstanceKeyFound64" Win64="yes" />
        <util:RegistrySearch
          Id="SqlInstanceFound64"
          Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\[SqlInstanceKey64]"
          Result="exists" Variable="SqlInstanceFound64" After="SqlInstanceKey64" Condition="SqlInstanceKeyFound64" Win64="yes" />
        <util:RegistrySearch
          Id="SqlVersion64"
          Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\[SqlInstanceKey64]\Setup" Value="Version"
          Variable="SqlVersion64" After="SqlInstanceKey64" Condition="SqlInstanceFound64" Win64="yes" />

 <PackageGroup Id="SQL2022Express">
      <ExePackage Id="SQL2022Express"
              DisplayName="SQL Server 2022 Express"
              Cache="yes"
              Compressed="no"
              PerMachine="yes"
              Permanent="no"
              Vital="yes"
              DetectCondition="SqlInstanceFound64"
              InstallCondition="INSTALLSQL=1"
              Name="Redist\SQLEXPR_x64_!(loc.LANG).exe"
              SourceFile="$(var.DependencyFolder)\SQLEXPR_x64_!(loc.LANG).exe"
              InstallCommand="/ACTION=Install /IACCEPTSQLSERVERLICENSETERMS [SQLQUIET] /HIDECONSOLE /FEATURES=SQLEngine /UpdateEnabled=0 /INSTANCENAME=PHARMSPEC /SQLSYSADMINACCOUNTS=Builtin\Administrators /SQLSVCACCOUNT=&quot;NT AUTHORITY\NETWORK SERVICE&quot; /SECURITYMODE=SQL /SAPWD=[SAPASSWORD] /NPENABLED=1 /TCPENABLED=1 /SKIPRULES=RebootRequiredCheck"
              UninstallCommand="/Action=Uninstall /INSTANCENAME=PHARMSPEC /FEATURES=SQL /QS /HIDECONSOLE">
        <ExitCode Value ="3010" Behavior="forceReboot" />
      </ExePackage>
    </PackageGroup>

日志中显示以下内容:

  • [0EE8:0EEC][2024-11-08T14:09:13]i000:将数字变量“SqlInstanceFound64”设置为值 1
  • [0EE8:0EEC][2024-11-08T14:09:13]i052:条件“SqlInstanceFound”计算结果为假。
  • [0EE8:0EEC][2024-11-08T14:09:13]i052:条件“SqlInstanceFound64”计算结果为真。
  • [0EE8:0EEC][2024-11-08T14:09:13]i000:将字符串变量“SqlVersion64”设置为值“14.0.1000.169”
  • [0EE8:0EEC][2024-11-08T14:09:13]i101:检测到的包:SQL2022Express,状态:存在,缓存:无
  • [0EE8:0EEC][2024-11-08T14:09:29]i052:条件“INSTALLSQL = 1”计算结果为真。
  • [0EE8:0EEC][2024-11-08T14:09:29]w321:跳过没有依赖提供程序的包的依赖项注册:SQL2022Express
  • [0EE8:0EEC][2024-11-08T14:09:29]i052:条件“INSTALLSQL = 0”计算结果为假。
wix
  • 1 1 个回答
  • 11 Views

1 个回答

  • Voted
  1. Best Answer
    Rob Mensching
    2024-11-09T08:02:24+08:002024-11-09T08:02:24+08:00

    SqlInstanceFound64变量被发现,该变量用于您的 DetectCondition 中,以指示已安装 SQL Express 2022。bundle 包不会安装已存在的内容。

    我认为您需要搜索 SQL Express 2022 独有的注册表项(或其他内容)。您现在正在查看的内容似乎是由许多版本的 SQL Express 设置的。

    • 0

相关问题

  • WiX 4 安装程序中引用多目标 C# 项目,未找到绑定名称

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    为什么这个简单而小的 Java 代码在所有 Graal JVM 上的运行速度都快 30 倍,但在任何 Oracle JVM 上却不行?

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    何时应使用 std::inplace_vector 而不是 std::vector?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Marko Smith

    我正在尝试仅使用海龟随机和数学模块来制作吃豆人游戏

    • 1 个回答
  • Martin Hope
    Aleksandr Dubinsky 为什么 InetAddress 上的 switch 模式匹配会失败,并出现“未涵盖所有可能的输入值”? 2024-12-23 06:56:21 +0800 CST
  • Martin Hope
    Phillip Borge 为什么这个简单而小的 Java 代码在所有 Graal JVM 上的运行速度都快 30 倍,但在任何 Oracle JVM 上却不行? 2024-12-12 20:46:46 +0800 CST
  • Martin Hope
    Oodini 具有指定基础类型但没有枚举器的“枚举类”的用途是什么? 2024-12-12 06:27:11 +0800 CST
  • Martin Hope
    sleeptightAnsiC `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它? 2024-11-09 07:18:53 +0800 CST
  • Martin Hope
    The Mad Gamer 何时应使用 std::inplace_vector 而不是 std::vector? 2024-10-29 23:01:00 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST
  • Martin Hope
    MarkB 为什么 GCC 生成有条件执行 SIMD 实现的代码? 2024-02-17 06:17:14 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve