For a .NET application installed using ClickOnce, is there any way to run a custom action during the uninstall process.
Specifically, I need to delete a few app related files (which I created on first run) and call a web service during the uninstall process.
Any ideas?
There is no way to do that with ClickOnce itself, but you can create a standard Setup.exe bootstrapper that installs the ClickOnce application and which has a custom uninstall action.
Note that this however this creates two entries in the Add /Remove programs, so you need to hide one of the entries (the clickonce app).
Your final problem will then be that there is no "silent uninstall" option on clickonce, so you could do something like this:
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "taskkill /f /im [your app process name]*"
objShell.Run "[your app uninstall key]"
Do Until Success = True
Success = objShell.AppActivate("[your window title]")
Wscript.Sleep 200
Loop
objShell.SendKeys "OK"
(Found here)
ClickOnce installs an Uninstall registry key in HKEY_CURRENT_USER which is accessible to your ClickOnce application.
The specific location is "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
You will have to search for the key with the DisplayName of your Application.
You can then wrap the normal uninstall action,
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
Microsoft.Win32.RegistryKey uninstallKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(registryKey);
if (uninstallKey != null)
{
foreach (String a in uninstallKey.GetSubKeyNames())
{
Microsoft.Win32.RegistryKey subkey = uninstallKey.OpenSubKey(a, true);
// Found the Uninstall key for this app.
if (subkey.GetValue("DisplayName").Equals("AppDisplayName"))
{
string uninstallString = subkey.GetValue("UninstallString").ToString();
// Wrap uninstall string with my own command
// In this case a reg delete command to remove a reg key.
string newUninstallString = "cmd /c \"" + uninstallString +
" & reg delete HKEY_CURRENT_USER\\SOFTWARE\\CLASSES\\mykeyv" +
MYAPP_VERSION + " /f\"";
subkey.SetValue("UninstallString", newUninstallString);
subkey.Close();
}
}
}