Domanda

Sto cercando di ottenere alcune informazioni da un file msi

ho usato:

Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
object installerInstance = installerType.CreateInstance(installerType);

Sono ben consapevole della possibilità di aggiungere riferimento al file C: \ windows \ system32 \ msi.dll, e cast installerInstance a WindowsInstaller.Install, ma dal momento che la mia applicazione verrà eseguita su molti sistemi operativi diversi (xp, 2003, Vista, 7, 2008) e processori (x86 -. x64), voglio usare in modo dinamico l'istanza

Il problema è che non riesco a raggiungere il tipo sottostante "WindowsInstaller.Installer", solo metodi Sistema .__ ComObject sono visibili ed eseguibile.

Come posso richiamare dinamicamente i metodi, come ad esempio "OpenDatabase", ecc ... dal oggetto sottostante?

È stato utile?

Soluzione

È necessario utilizzare riflessione per richiamare i metodi. Ecco un esempio invocando la Eseguire metodo di Windows script host :

// obtain the COM type:
Type type = Type.GetTypeFromProgID("WScript.Shell");
// create an instance of the COM type
object instance = Activator.CreateInstance(type);
// Invoke the Run method on this instance by passing an argument
type.InvokeMember(
    "Run", 
    BindingFlags.InvokeMethod, 
    null, 
    instance, 
    new[] { @"c:\windows\notepad.exe" }
);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top