시스템에서 메소드 호출 .__ comobject 기본 유형
-
19-09-2019 - |
문제
MSI 파일에서 정보를 얻으려고합니다.
나는 사용했다 :
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
object installerInstance = installerType.CreateInstance(installerType);
파일 C : Windows System32 MSI.dll에 대한 참조를 추가하고 설치 장치를 WindowsInstaller.install로 캐스트하는 옵션을 잘 알고 있지만 응용 프로그램이 여러 다른 운영 체제에서 실행되기 때문에 (XP, 2003, Vista. , 7, 2008) 및 프로세서 (x86 -x64), 인스턴스를 동적으로 사용하고 싶습니다.
문제는 기본 "WindowsInstaller.installer"유형에 도달 할 수 없다는 것입니다.
기본 객체에서 "opendatabase"등과 같은 방법을 동적으로 호출하려면 어떻게해야합니까?
해결책
방법을 호출하려면 반사를 사용해야합니다. 다음은 다음을 호출하는 예입니다 운영 의 방법 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" }
);
제휴하지 않습니다 StackOverflow