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 7974681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:26:42+00:00 2026-06-04T08:26:42+00:00

The answer probably involves a custom uninstall action, but it seems like such a

  • 0

The answer probably involves a custom uninstall action, but it seems like such a major oversite and something that every application would want, so I thought I’d see if there is something easy I am missing.

I have a couple of projects create in Visual Studio 2008 using C#, Winform projects. One uses click-once install, and one use a setup project. They both allow you to leave the application running when you uninstall. On Windows 7 you do get a warning, but have the option to leave it running anyway… on XP not even a warning.

Call me crazy, but the thought of all of my program files being removed, and my app still left running, doesn’t sound like a good design at all. Memories of GPFs come to mind, or the way .NET uses delay loading for DLLs, also could be a problem when the DLL needs to be loaded, and is gone.

So is there an easy way to not allow uninstall if your app is still running?

I’m using C# but I’m using the VB.NET Single Instance class to make sure my app only runs once, so maybe something that takes advantage of that as opposed to creating a mutex to check for?

Also my app only allows “per user” installs, not “all users”, so I shouldn’t have to worry about my app running in another session (if it is, it is OK to stay running because it should be 100% its own copy).

Edit: Since I’m not finding anything else, I’ve tried the mutex idea and it isn’t working. Here is my code:

In the app I have this to create the named mutex and keep alive while app running:

        System.Threading.Mutex m = new System.Threading.Mutex(true, "SafeShare");

        SingleInstanceApplication.Run(TabForm, NewInstanceHandler);

        GC.KeepAlive(m);

In the uninstall action I have this to loop until they exit (since it doesn’t appear to be easy to provide a cancel option):

            while (true)
            {
                bool createdNew;
                System.Threading.Mutex m = new System.Threading.Mutex(true, "SafeShare", out createdNew);
                m.ReleaseMutex();
                if (createdNew)
                    break;
                MessageBox.Show(null,"Close XXX and click OK to continue uninstall.","Uninstall");
            }

createdNew is never set in the uninstall action, almost like it is running under a different session or something. I haven’t tried adding Global\ to the mutex name, but that would not work well for my app anyway because I do per-user installs, so one install should be able to keep running on another session even if one is uninstalled.

  • 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-06-04T08:26:43+00:00Added an answer on June 4, 2026 at 8:26 am

    Short answer is there is no easy way to do this because it isn’t something Microsoft wants you to do.

    My answer did end up using a mutex, once I got the code correct it seems to work fine.

    In the app I do:

    System.Threading.Mutex m = new System.Threading.Mutex(true, "MyMutexNameHere");
    SingleInstanceApplication.Run(TabForm, NewInstanceHandler);
    GC.KeepAlive(m); 
    

    The SingleInstanceApplication.Run line is what runs your app, I’m using the VB.NET framework.

    In the custom uninstall action I do:

    while (true)
    {
       bool createdNew;
       System.Threading.Mutex m = new System.Threading.Mutex(true, "MyMutexNameHere", out createdNew);
       m.Close();
       if (createdNew)
          break;
       MessageBox.Show(null,"Close XXX and click OK to continue uninstall.","Uninstall");
    }    
    

    At first I was using m.ReleaseMutex() instead of m.Close() which I found out was throwing an exception because I didn’t own the mutex. Close was what I should have been using, just to make sure my copy was closed before I checked again (otherwise createNew was never true, if it wasn’t true the first time).

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

Sidebar

Related Questions

a simple and theoric question, the answer is probably one, but I would like
I suspect the answer is probably no, but just in case, is there a
This has probably been answer already but I am trying to return the primary
The answer to this is probably right under my nose, but I am not
This is probably a simple one to answer, but I'm stuck, so here goes.
This is probably got a simple answer to it, but I am having problems
Probably it has been asked before but I cannot find an answer. Table Data
This is probably a really dumb question with a simple answer but... I am
I'm working with MEF right now, but the answer I'm looking for probably is
Okay, so the answer is probably obvious, but I don't know the correct way

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.