以编程方式安装 VFPOLEDB 时出现异常

Exception while installing VFPOLEDB programmatically

我正在尝试通过控制台应用程序安装 VFPOLEDB 驱动程序。

我试过这样做

public void InstallVfpOledb()
{
            Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            try
            {
                Installer installer = (Installer)Activator.CreateInstance(type);
                installer.InstallProduct(@"C:\VFPOLEDBSetup.msi");
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
}

所以当我 运行 程序时,我得到以下异常:

System.Runtime.InteropServices.COMException (0x80004005): InstallProduct,PackagePath,PropertyValues at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at WindowsInstaller.Installer.InstallProduct(String PackagePath, String PropertyValues) at installtest.Program.Main(String[] args) line 22

我相信 InstallProduct 方法有路径和 属性 值作为参数。

我错过了我猜的那些值。

任何人都可以为我指出正确的方向吗?

这个适合我:

// using Microsoft.Deployment.WindowsInstaller in 
// Microsoft.Deployment.WindowsInstaller.dll

try
{
    Installer.InstallProduct(@"C:\VFPOLEDBSetup.msi","");
}
catch (Exception e)
{
    Console.Write(e.Message);
}

如果不是运行管理员,它会请求权限。