0

I have developed desktop application in C# VS 2010.

I have setup created using visual studio installer & custom action.

How can we check application is opened user trying to install upgraded version /uninstall application user get notified message through custom action?

Thanks in advance

  • Possible duplicate of [Checking if a Windows application is running](http://stackoverflow.com/questions/4722198/checking-if-a-windows-application-is-running) – Sinatr Aug 30 '16 at 07:50
  • how can we check duplicate of check duplicate instance in C# ? – Vilas Patil Aug 30 '16 at 07:57
  • This is not a dublicate of the linked question, as it is not checking from the application itself, but from the installer. – Marcel Theis Aug 30 '16 at 07:59
  • @MarcelTheis, this is why it's *possible* duplicate. I don't know what custom action is. If it's a normal C# code (and it looks to me [as such](https://msdn.microsoft.com/en-us/library/d9k65z2d(v=vs.80).aspx)), then you can use global `Mutex` to check if your own application is already running (this solution is mentioned as one of the answer in linked question). – Sinatr Aug 30 '16 at 08:05
  • Actually custom action is what can be done during an installation process. – Marcel Theis Aug 30 '16 at 08:06
  • You are right, the second answer of that question could do that, if it was correctly implemented as in the comments mentioned. See my answer, I´m working with IDs rather then names. – Marcel Theis Aug 30 '16 at 08:08
  • I have created setup vs 2010. Eg: I have created one setup Tool1 application setup in that i have added another Exe for desktop short cut which is Home.exe. when we installed setup Home desktop shortcut created on desktop. – Vilas Patil Aug 30 '16 at 08:18
  • I have created setup vs 2010. Eg: I have created one setup Tool1 application setup in that setup i have added another Exe for desktop short cut which is (Home.exe). when we installed setup Home desktop shortcut created on desktop. Clicked on desktop shortcut it open home screen with button ,when click on button it show installed application means Tool1 in below list. so how to check desktop shortcut through application opened user trying install/uninstall application how get user notified message. – Vilas Patil Aug 30 '16 at 08:24

2 Answers2

1

There is no support for anything to do this in Visual Studio setups. This is because all Visual Studio install custom actions are run almost at the end of the install after all the files are installed, so it's no use for checking anything "before" the install.

In fact many installers have no support for this because it's not needed. Windows will check to see if any in-use files (and their loaded Dlls) are going to be replaced, and will show the user a Files-In-Use dialog box asking what the user wants to do, which is to close down the app or not (which may require a reboot). Therefore the user has the choice of what to do, and is not required to shut down the app. So there is no need to do anything at all about any possible files-in-use situation. The user will already get a dialog about in-use files if there is an issue.

More thorough applications integrate with the Restart Manager such that they save their state, shut down automatically, and Windows will restart them after the update with their command line that means they restore state, the user loses no data and carries on.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
0

Propably you could do something like this:

/// <summary>
    /// Prüft ob die Anwendung bereits ausgeführt wird.
    /// </summary>
    /// <returns>
    /// <c>true</c> wenn die Anwendung bereits läuft,
    /// anderenfalls <c>false</c>.
    /// </returns>
    /// <remarks>n/a</remarks>
    private static bool AlreadyRunning()
    {
        Process current = Process.GetCurrentProcess();
        Process[] processes = Process.GetProcessesByName(
                                current.ProcessName);
        foreach (Process process in processes)
        {
            if (process.Id != current.Id)
            {
                if (Assembly.GetExecutingAssembly().Location
                    .Replace("/", "\\") == current.MainModule.FileName)
                {
                    return true;
                }
            }
        }
        return false;
    }


This can only be done, if you keep the assymblies properties the same (except the version number) otherwise it would be an other application for the system and you would only be able to search the process by name.

Marcel Theis
  • 303
  • 1
  • 12