Click to See Complete Forum and Search --> : Run uninstaller


Runt888
July 17th, 2006, 05:07 PM
I need to be able to launch an uninstaller from my code and wait until it is finished. Right now I use ShellExecuteEx with an open verb, and set the file to "c:\windows\system32\MsiExec.exe". Then I set the parameter string to be "/x{packageID}". This works great. However, I'm nervous about hardcoding in the path to the uninstaller. So I have a couple questions:

1. Obviously I should use a function to get the path to the system directory (ie, GetSystemDirectory). However, will MsiExec.exe always be there (assuming Windows Installer is installed on the machine)?

2. Would it be better to use the Windows Installer API? They have a couple functions that deal with uninstalling, but I haven't been able to find any examples of how to call those functions from C++.

Thanks for any help!

Kelly

Boris K K
July 19th, 2006, 12:10 PM
You can use the MSI API, for example

MsiInstallProduct(
LPCTSTR szPackagePath,
_T("REMOVE=ALL")
);


But then you will have to hard-code the name of "msi.dll". I would not recommend linking to msi.lib because your application won't run if MSI is not installed. Use LoadLibrary(Ex) and GetProcAddress instead.

Runt888
July 21st, 2006, 12:44 PM
Thanks for the reply. I ended up using MsiConfigureProduct so I could use the package code instead of the path, but you definately put me on the right track. Thanks again!

Kelly