开发者

Prevent uninstall in setup project with OnBeforeUninstall

开发者 https://www.devze.com 2023-01-27 01:53 出处:网络
I overrode OnBeforeUninstall to stop my application\'s setup project from uninstalling itunder certain circumstances, but it seems like it is just not being called and has no effect.

I overrode OnBeforeUninstall to stop my application's setup project from uninstalling it under certain circumstances, but it seems like it is just not being called and has no effect.

protected override开发者_开发知识库 void OnBeforeUninstall(IDictionary savedState)
{
    if (ApplicationIsBusy())
        throw new ApplicationException("Prevent uninstall while application busy.");
}

I am able to cancel uninstall by overriding the Uninstall method, but by then the setup project has already closed my application. How do I "fail" an uninstall attempt when my application is busy before the setup project tries to close it when it is running and interrupts my worker process?


Make sure that in the setup project you chose the custom action for uninstalling, that s probably your case.


Before calling your custom code, call the base.OnBeforeUninstall(savedState) so that registered delegates receive the event thereby allowing your custom code to execute before the uninstall.

protected override void OnBeforeUninstall(IDictionary savedState)
{
    // Add this
    base.OnBeforeUninstall(savedState);

    if (ApplicationIsBusy())
        throw new ApplicationException("Prevent uninstall while application busy.");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消