Reputation: 21
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
Upvotes: 0
Views: 314
Reputation: 20780
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.
Upvotes: 1
Reputation: 313
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.
Upvotes: 0