Question

Je suis en train d'obtenir des informations à partir d'un fichier msi

je:

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

Je suis bien conscient de la possibilité d'ajouter une référence au fichier C: \ windows \ system32 \ msi.dll et installerInstance coulé à WindowsInstaller.Install, mais depuis mon application fonctionnera sur de nombreux systèmes d'exploitation (XP, 2003, Vista, 7, 2008) et les processeurs (x86 -. 64 bits), je veux utiliser dynamiquement l'instance

Le problème est que je ne peux pas atteindre le sous-jacent de type « WindowsInstaller.Installer », seules les méthodes System .__ ComObject sont visibles et exécutable.

Comment puis-je invoquer dynamiquement des méthodes, telles que « OpenDatabase » etc ... de l'objet sous-jacent?

Était-ce utile?

La solution

Vous devez utiliser la réflexion pour appeler des méthodes. Voici un exemple d'appeler la méthode Exécuter de scripts Windows :

// 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" }
);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top