Custom Application Installer using .NET RRS feed

  • Question

  • Hi All,

    Hope you're having a great day. I created a custom installer for my application through .NET WinForms, and quite recently had to embed an uninstaller in the same installer as well. So the flow goes like:

    • The installer runs and checks for the installed application.
    • If the application is present, it asks the user to uninstall the previous version before installing the newer version.
    • If the application is not present, the wizard takes user to the installation screen.

    My application, along with other sub apps, also has a windows service that runs in the background. So when I uninstall the application, I do the following:

    1. I find and uninstall the background Windows Service.
    2. I delete all the registry entries.
    3. Finally I uninstall all the application files present in the installation directory.

    The issue I am facing begins at step 3. Since the Windows Service is not fully uninstalled without computer restart, rather it is only marked for deletion, I am unable to completely wipe out the app installation directory, and some files remain there. After the restart, I have to manually go and delete all those files. Can anybody help me on how to proceed with this and solve my issue?

    Possible ways of doing this in my mind are:

    1. The uninstaller somehow completely uninstalls the service without a restart, so I am able to wipe the installation directory fully.
    2. I configure a sort of a one time event in windows that triggers after the restart and automatically deletes the remaining files from installation directory.

    Kindly guide me on how to proceed with this. Your help would be highly appreciated. Thanks & Regards.

    PS: I've made a custom installer because it has to have a custom theme, and it needs to download files from internet, and could require further enhancements down the road.

    Wednesday, February 19, 2020 5:41 PM

All replies

  • The first mistake you made was creating your own installer. All the commercial installers (and even WiX I believe) can do everything you want including the custom downloading of file. That is what they are built for. Just take a look at the VS Installer, SQL Installer, etc. They all do this. I strongly recommend you use one of the existing tools that already properly integrate with MSI.

    As for the service issue the problem is your step #1. You cannot uninstall the service if it is running. It is never a requirement that a machine be rebooted to uninstall a service. The only time a reboot is required is if the uninstaller does it wrong. The correct approach to uninstalling a service.

    1. Stop the service if it is running.

    2. Uninstall the service.

    That's it. Windows will handle the rest. You can immediate reinstall the service if you want. The reason you're requiring a reboot is because you uninstalled a running service.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, February 19, 2020 9:32 PM
  • Hi ShujaARizvi,

    Thank you for posting here.

    Here is a link on how to make an app delete itself immediately.

    Although it is a long time ago, you can give it a try.

    How To Make Your Application Delete Itself Immediately

    As for how to delete related folders after restart, I think using batch files would be an option.

    Note: You can use the "rd /s /Q path" command to delete the corresponding folder, and then use the "del /s /Q path" command to delete the bat file itself. And you can put the bat file to startup folder to run it after the computer start.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 20, 2020 3:30 AM
  • Hello CoolDadTx, 

    Thank you for taking out time to reply. I am pretty sure your answer is the solution to my problem, but the issue is, I've set my service's CanStop to false, so I am unable to stop the service during uinstallation. I can't change the CanStop because its a requirement. Can you suggest any resolution to this?

    Thursday, February 20, 2020 4:51 PM
  • The resolution is to not set CanStop. This property means that the SCM cannot stop the service. Since only an admin can stop services and admins can do anything this isn't really useful. If an admin says stop then the service stops. Making the service stoppable solves your problem.

    But let's review what would happen if you leave CanStop true. An admin can still stop the service just the SCM cannot. As an admin I can terminate any process running on the OS except the TCB processes that are defined in the kernel. Therefore you setting your service such that the SCM cannot stop doesn't actually prevent an admin from stopping it. Hence the service is stoppable, just not by normal means. This property is really pretty useless in my experience.

    However if you really want to prevent the SCM from stopping the service, even though an admin still can, then all you need to do is do the same thing that an admin would do. Get the service process using Process.GetProcessesByName. Once you have the Process call Kill and the process terminates, irrelevant of your CanStop flag.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, February 20, 2020 5:05 PM