我需要提示用户在程序卸载时关闭services.msc管理单元。我该怎么做?
答案 0 :(得分: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>