Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:43:23+00:00 2026-05-26T22:43:23+00:00

my program installs my custom service and register it. Now what I am trying

  • 0

my program installs my custom service and register it. Now what I am trying to do is to unregister the service and delete all files after uninstall. I am using Visual Studio and Setup and Deployment and the Installer class, I have overridden a few methods that I am presenting below:

protected override void OnAfterUninstall(IDictionary savedState)
{
    base.OnAfterUninstall(savedState);
    string directory = "C:\\Program Files (x86)\\MyService\\";
    if (System.IO.Directory.Exists(directory))
    {
        string[] files = System.IO.Directory.GetFiles(directory);
        foreach (string file in files)
        {
            System.IO.File.Delete(file);
        }
        System.IO.Directory.Delete(directory);
    }
}

protected override void OnBeforeUninstall(IDictionary savedState)
{
    base.OnBeforeUninstall(savedState);
    string path = "-u \"C:\\Program Files (x86)\\MyService\\AA_service.exe\"";
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "C:\\Program Files (x86)\\MyService\\InstallUtil.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = path;


    Process.Start(startInfo);

}

It does not unregister service and it does not delete application folder. Can anyone suggest me what am I doing wrong?

//edit

now it is trying to remove files but I am getting access denied error on uninstall. Files I am trying to delete are .exe, .dll and some others

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:43:24+00:00Added an answer on May 26, 2026 at 10:43 pm

    Did you add the custom actions into the MSI? If you don’t have a custom action fire for your uninstall event then I’m not sure if these events will be called. Is there any reason why you are using the before and after install events instead of overriding the “uninstall” command?

    If you don’t call the Install function for the component, then the installer won’t call the uninstall function either. You can program a messagebox into the uninstall (or a System.Diagnostics.Debugger.Attach()) if you want to see whether the code is executing or not.

    Also as a matter of portability, I highly recommend that you use the Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) command to find the program files directory. This will port across x64 and x86 as well as any future revisions to the program files directory in the future.

    Secondly I would use the Path.Combine function as well to safely merge the folders together.

    EDIT:
    I think you may be misusing the installation procedure. The custom action of the installer is to “register” the service once it has been installed by the MSI. It is also to unregister the service before it is then deleted by the MSI.

    Go get a copy of WIX or use the MSI builder in Visual Studio. Drop your project output for your service into the project, setup the custom actions to call on your service exe and then the MSI will handle the install/uninstall for you. THe custom action will be called and register/unregister your service with the cache.

    Be very careful though, if you need to upgrade there is a bug in the behaviour of the service installer, it is not able to succesfully upgrade or downgrade without you wiring the MSI properly to handle all the sequences that can occur.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a little installer, which installs to program files. I run the installer
We have an app that currently installs itself into 'program files\our app', and it
I have a setup project that installs my app to the typical program files
I have a CAB file that installs our program to Windows CE. I have
I am trying to write a local program management and install system for my
I'm trying to setup a SQL database for a local program management and install
I've a custom installer program that has worked fine, but it asks the user
Does anyone know of a method to remove all webapps deployed from .war files
I'm trying to call a custom action within my Setup & Deployment project to
My program installs a driver, which has different versions compiled for XP, Win2003, Vista/Win2008,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.