0

I created WPF application and created setup and installed on the system (manually). Now I want to uninstall this application by the c# program. By this way we want to install new version of this application.But how? thanks.

10
  • Can you please try to be a bit more specific? The question as it stands now is extremely vague, which makes providing any kind of helpful information / answer unnecessarily hard. Without any more information I'd simply suggest to copy the new files and replace any existing / old files... Commented Jul 13, 2017 at 11:25
  • I want to uninstall program by software name like (demo.exe) using the c# code. Bot How? or any other way. Commented Jul 13, 2017 at 11:52
  • Have you created your own vdproj as installer? If so then there is a way to achieve what you intend by running a script or an exe in the install command Commented Jul 13, 2017 at 11:55
  • I created setup with the help Installshield. I think you know that process of Iinstallshield. And now I want to uninstall the project by separate C# program. Commented Jul 13, 2017 at 12:02
  • 1
    I have never used InstallShield before. But, what I see is there is an option to set custom action on Install command in InstallShield as well. So you may want to try execute a normal C# exe application which can uninstall your previously installed version of application while installing your new version of application . Commented Jul 13, 2017 at 12:14

2 Answers 2

0

This is the way I would suggest you to go for achieving what you are up to! Note: The way I explain is what you can do in normal visual studio installer project. For install shield, the steps may look different but it follows same strategy.

  1. File System on Target machine -> add a Special Folder, select System Folder
  2. Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it.
  3. Override default properties as: Condition = Not Installed, Permanent = True, System = True, Transitive = True Vital = False
  4. Create a new shortcut under the Application Folder, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe.
  5. Rename the shortcut to ‘Uninstall Your Application’.
  6. Set the Arguments property to /x [ProductCode] (there is a space in between x and [)
  7. Build the project

After you are done with these steps, you would have created your own uninstaller for your application. Now, when you install you application for first time, it will automatically paste the uninstaller exe in the install folder. Next time when you install, the installer should find and execute this uninstaller before installing newer version. For this, you can create a vb script batch file to invoke and execute your uninstaller exe.

Dim WSHShell
Dim oFSO
Dim EXEPath

Set WSHShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not WSHShell Is Nothing Then
    EXEPath = "C:\Program Files (x86)\Your Application Location\Uninstall Your Application.exe"

    If oFSO.FileExists(EXEPath) Then
        WSHShell.Run(EXEPath)
    End If
End If

Store this script as uninstaller.vbs in you application and attach this file in your Application Folder. Now, in your customer actions for install, you need to execute this script before you perform installation.

I hope this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

Any video/demo available for these steps. Actually 1-6 steps are very tough for us. So please help me.
@user4667380 nothing as such in my knowledge! But, I have been working on something similar in my project and I can show you mine which is in normal installer project
0

If you just want to install a setup that you built and installed, and it's (for example) a Visual Studio setup project that generated an MSI file then you just need to know the ProductCode of your setup.

Then (in C#) you'd P/Invoke to MsiConfigureProduct and pass in the ProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_ABSENT).

Otherwise can use the command msiexec /x {productcode} with whatever other command line options you choose.

The problem will be that you are trying to uninstall a product from which a program is still running, therefore there's a kind of deadlock.

If you were using WiX there's this:

http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_uninstall_shortcut.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.