Search code examples
c#installationoledbvisual-foxprofailed-installation

Exception while installing VFPOLEDB programmatically


I am trying to install VFPOLEDB driver via a console application.

I tried doing something like this

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());
            }
}

So when I run the program I get the following exception:

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

I believe InstallProduct method has path and property values as parameters.

I am missing those values I guess.

Can anyone point me in the correct direction for the same?


Solution

  • This one works for me:

    // using Microsoft.Deployment.WindowsInstaller in 
    // Microsoft.Deployment.WindowsInstaller.dll
    
    try
    {
        Installer.InstallProduct(@"C:\VFPOLEDBSetup.msi","");
    }
    catch (Exception e)
    {
        Console.Write(e.Message);
    }
    

    It asks for permission if not run as administrator.