Programmatically uninstalling a program using C#
Earlier we released an application <application name>
. Later a new version of the application was released but with different application name <company name> <application name>
. But both these applications put files in the same program folder. But we have two different ve开发者_如何学运维rsions listed in uninstall programs.
Now that we want to release a newer version. An we want to uninstall the very first version from the user's pc. how can I achieve this using c#. We are using windows 7 64 bit (application is 32 bit and installed in x86 folder).
I don't have the application setup neither the application key
If you have an installer project you can specify this in the installer properties.
See: VS2008 Setup Project: Uninstalling the previous MSI
If you're application cannot detect it's early version (Different Name) ,than you probably should delete Data from Places where these 2 Application interferes . You could do that with File.Delete();
but if these Files are somewhere where Application has not permission's you should force it run as Admin by Adding a Manifest File and replace that line.
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Have a look at the COM WindowsInstaller classes. You will need to add a reference to the WindowsInstaller class to get access to it. From here you can browse the MSI and perform actions on it if required. I use this in my post build to modify the archive to fix a... undocumented functionality of Visual Studio.
// Create an Installer instance
MsiInstaller = Activator.CreateInstance(Type.GetTypeFromProgID("WindowsInstaller.Installer")) as WindowsInstaller.Installer;
// Open the msi file for Read/Write
MsiDatabase = MsiInstaller.OpenDatabase(MsiFile.FullName, MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);
精彩评论