3

我需要提示用户在程序卸载时关闭 services.msc 管理单元。我怎么做?

4

1 回答 1

0

您需要编写自定义操作来做到这一点。您可以使用Process检查 services.msc 是否已加载到 mmc 中。

  [CustomAction]
    public static ActionResult CustomAction1(Session session)
    {
        foreach (Process getProcess in Process.GetProcesses())
        {
            if (getProcess.ProcessName.Contains("mmc"))
            {
                if (getProcess.MainWindowTitle == "Services")
                {
                    session["SERVICES_MSC"] = "Running";
                    break;
                }
            }
        }

        return ActionResult.Success;
    }

在卸载中调用自定义操作并根据SERVICES_MSC属性停止卸载。

<Binary Id="Check_Services" SourceFile="..\TestProject\bin\Release\TestProject.CA.dll" />
<CustomAction Id="CHECK_SERVICES" BinaryKey="Check_Services" DllEntry="CustomAction1" Return="check" />

<CustomAction Id="STOP_INSTALLATION" Error="Services.msc is running.Please close that Window before uninstall the setup." />

在 Install Execute 序列中调用自定义操作。

  <Custom Action="CHECK_SERVICES" After="InstallValidate">REMOVE ~= "ALL"</Custom>
  <Custom Action="STOP_INSTALLATION" After="CHECK_SERVICES">(REMOVE ~= "ALL") AND SERVICES_MSC</Custom>
于 2013-06-07T13:24:41.527 回答