I need to prompt user to close services.msc snap-in on program uninstall. How do I do that?
Asked
Active
Viewed 671 times
3
-
What is your goal with this? – Tom Blodget Jun 07 '13 at 21:56
-
Please see http://stackoverflow.com/questions/5321825/verify-if-a-service-is-marked-for-deletion – user10101 Jun 09 '13 at 14:14
-
Sometimes my service cannot be registered because of services applet running. – user10101 Jun 09 '13 at 14:22
-
That's an interesting problem. I don't have a ready answer. There are two possible, non-exclusive approaches: 1) Help the uninstaller user understand that uninstallation should not proceed/won't be fully complete until all processes release handles to the service, or 2) Help the installer user understand that installation cannot proceed/will fail unless all processes release handles to the service scheduled for deletion. Detecting (1) might be harder, but could be narrowed to just detecting the services snap-in, as you suggest. Detecting (2) would still require a custom action. – Tom Blodget Jun 09 '13 at 16:46
1 Answers
0
You need to write custom action to do that. You can use Process to check whether services.msc is loaded in mmc or not.
[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;
}
Calls the Custom action in uninstall and stop the uninstallation based on the SERVICES_MSC property.
<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." />
Inside the Install Execute sequence call the custom actions.
<Custom Action="CHECK_SERVICES" After="InstallValidate">REMOVE ~= "ALL"</Custom>
<Custom Action="STOP_INSTALLATION" After="CHECK_SERVICES">(REMOVE ~= "ALL") AND SERVICES_MSC</Custom>

Vinoth
- 1,975
- 21
- 34
-
Thank you. But if you first run mmc and then load services applet by File->Add/Remove Snap-In and leave focus on Console Root then window title will not contain "Services". Also the name of the applet might be localized to a different language. – user10101 Jun 07 '13 at 19:54