-1

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user4667380
  • 61
  • 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... – bassfader Jul 13 '17 at 11:25
  • I want to uninstall program by software name like (demo.exe) using the c# code. Bot How? or any other way. – user4667380 Jul 13 '17 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 – praty Jul 13 '17 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. – user4667380 Jul 13 '17 at 12:02
  • My application name is Scheduler.exe. This is installed on my computer under the directory of C:\Program Files (x86)\SchedulerApp. Here exe and dll are situated. – user4667380 Jul 13 '17 at 12:03
  • I can uninstall by the control Panel but i want to from c#. – user4667380 Jul 13 '17 at 12:04
  • 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 . – praty Jul 13 '17 at 12:14
  • what will be c# code for that? – user4667380 Jul 13 '17 at 12:34
  • @user4667380. You would have to create an uninstaller package first. This package should be copied to client when you install. And then in your install command, you would have to add a customer action to invoke this unistaller. To know how to create an uninstaller package in c# and invoke it you might have to google. Check this trail for some lead: https://stackoverflow.com/questions/30067976/programatically-uninstall-a-software-using-c-sharp – praty Jul 13 '17 at 13:04
  • @user4667380, I have given you a sample of what you can do in answer section. Hope it works out for you! – praty Jul 13 '17 at 13:54

2 Answers2

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!

praty
  • 535
  • 2
  • 9
  • Any video/demo available for these steps. Actually 1-6 steps are very tough for us. So please help me. – user4667380 Jul 13 '17 at 14:47
  • @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 – praty Jul 13 '17 at 14:51
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

PhilDW
  • 20,260
  • 1
  • 18
  • 28