Usually, I use the below vb.net function to Uninstall our ClickOnce applications on our user's PCs. I hope this help you. You can convert to C# here if you use C#.
Private Sub KillandClear()
Try
Me.Cursor = Cursors.WaitCursor
'************* Killing the current running process *************
Dim proce2 As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("****YourApp****")
For Each process In proce2
process.Kill()
Next
'************* Deleting the Local Appdata *************
Dim rootFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Apps\2.0"
Dim foldersToDelete As List(Of String) = Directory.GetDirectories(rootFolder, "YourApp*", SearchOption.AllDirectories).ToList()
For Each folder In foldersToDelete
Directory.Delete(folder, True)
Next
'************* Clearing the Registry *************
Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", True)
Dim subKeys() As String = regKey.GetSubKeyNames()
For Each subKey In subKeys
Dim appKey As RegistryKey = regKey.OpenSubKey(subKey, True)
Dim uninstallString As String = appKey.GetValue("UninstallString")
If uninstallString IsNot Nothing AndAlso uninstallString.Contains("****YourApp****") Then
regKey.DeleteSubKeyTree(subKey)
End If
Next
'************* Deleting the Desktop Shortcuts *************
For Each FName As String In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop)
If FName.StartsWith("****YourApp****") Then
My.Computer.FileSystem.DeleteFile(FName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
End If
Next
Catch ex As System.Exception
'MessageBox.Show("Error Message:" & vbCrLf & ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub