2

msiファイルからいくつかの情報を取得しようとしています

私が使用した:

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

ファイルC:\ windows \ system32 \ msi.dllへの参照を追加し、installerInstanceをWindowsInstaller.Installにキャストするオプションをよく知っていますが、アプリケーションはさまざまなオペレーティングシステム(xp、2003、vista)で実行されるためです。 、7、2008)およびプロセッサ(x86-x64)、インスタンスを動的に使用したい。

問題は、基になる「WindowsInstaller.Installer」タイプに到達できないことです。System.__ ComObjectメソッドのみが表示され、実行可能です。

基になるオブジェクトから「OpenDatabase」などのメソッドを動的に呼び出すにはどうすればよいですか?

4

1 に答える 1

4

メソッドを呼び出すには、リフレクションを使用する必要があります。WindowsScriptHostのRunメソッドを呼び出す例を次に示します。

// 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" }
);
于 2009-11-10T09:39:00.713 に答える