سؤال

أحاول الحصول على بعض المعلومات من ملف MSI

انا إستعملت:

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

أنا أدرك جيدا خيار إضافة مرجع إلى الملف c: windows system32 msi.dll، و cast installerinstance إلى windowsinstaller.install، ولكن نظرا لأن طلبي سيعمل على العديد من أنظمة التشغيل المختلفة (XP، 2003، Vista ، 7، 2008) ومعالجات (X86 - X64)، أريد استخدام المثيل ديناميكيا.

المشكلة هي أنه لا يمكنني الوصول إلى نوع "WindowsInstaller.installer" الأساسي، والنظام فقط .__ طرق combject مرئية ويمكن تنفيذها.

كيف يمكنني استدعاء طرق ديناميكيا، مثل "opendatabase" إلخ ... من الكائن الأساسي؟

هل كانت مفيدة؟

المحلول

تحتاج إلى استخدام التفكير لاستدعاء الأساليب. إليك مثال استدعاء يركض طريقة يستضيف Windows Script.:

// 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" }
);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top