也许对于您的情况来说,了解"/x"参数已经足够了。关于此,有两点需要注意:
更安全的做法是在命令行中添加一个"REBOOT=R"部分。您还可以添加日志文件路径:
msiexec /x "..." /qn REBOOT=R /L*v "c:\mylogdir\mymsi.log"
第二点,不要试图更改“缓存”中的任何内容。您甚至不需要理解它。如果缓存的软件包损坏,则无法进行常规卸载,这可能会导致计算机处于“需要支持”的状态。
因为您的问题最初是关于C#的...您不必使用msiexec:
a)使用原始的C/C++ API和函数MsiInstallProduct()或MsiConfigureProduct()。
MSDN参考:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa370315(v=vs.85).aspx
您需要使用互操作才能在C#中使用它。
或者b)
使用Windows Installer对象。
例如,这个相关案例已经在stackoverflow上得到了答案:
Programmatically installing MSI packages
但是使用此功能需要物理软件包,也用于卸载。
通过轻微的间接性,这是更好的卸载代码:
首先,在项目中添加对COM对象“Microsoft Windows Installer Object Library”的引用。
using WindowsInstaller;
public static class MyMsiLib
{
public static void Uninstall(string productCode)
{
Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
Installer installer = (Installer)Activator.CreateInstance(type);
installer.UILevel=msiUILevelNone;
installer.ConfigureProduct(productCode, 0, msiInstallStateAbsent);
}
}
在这里,UILevel属性被硬编码设置为静默的UI级别,因为您似乎希望如此。其他属性也是如此。请参见MSDN文档,例如上面链接中提到的内容。
当然,“真正的程序员”使用原始API而不是“安装程序对象”:-) 但对于小目的来说,它已经足够了。而且更容易。