Programmatically uninstall a program?

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

I am writing a C# program that needs to see if a particular program is
installed (it would be listed in the "Add or Remove Programs" list from the
Control Panel) and uninstall it.
Is there a way to do this?.. Thanks for any help... Bryan
 
All this information is stored in the registry. You can take a look at the
registry key LocalMachine/Software/Installer/Products. There might be a
better way though.
 
Thanks for the reply. I'm sure I can get a list of the currently installed
programs, but what I really need to know is how to uninstall them. Any
ideas?
 
Bryan,
To expand on what Peter was talking about, look for a key named
UninstallString. The key holds a value that Add\Remove Programs executes
when you click "Remove". You can execute the UninstallString from a command
line or programmatically. I have pasted an example below. I use Windows XP
Professional, so the key path may vary. HTH

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserD
ata\S-1-5-18\Products\9040110900063D11C8EF10054038389C\InstallProperties
DisplayName: Microsoft Office Professional Edition 2003
UninstallString: MsiExec.exe /I{90110409-6000-11D3-8CFE-0150048383C9} <-
You can execute this from the command line.
 
If the software was installed with Windows Installer, then you can use the
Windows Installer API, which has the ability to list all installed programs,
features, and components, as well as version information and lots more. You
can call functions to uninstall what you need. See
http://msdn.microsoft.com/library/d...y/en-us/msi/setup/about_windows_installer.asp

If Windows Installer hasn't been used, the you could use the technique from
Jason (assuming the installer properly wrote to the registry - if the
install was home-brewed, you may not be able to uninstall it automatically).
 
Thanks everyone for your help. I am able to use both techniques to
accomplish my task.
 
Back
Top