我在 Silverlight 5 中有一个签名的、受信任的应用程序(并且知道它工作正常并且启用了 AutomationFactory)。但是,无论我做什么,当我尝试查询注册表时,都会收到类型不匹配的 COM 异常,这无济于事。视窗 7 IE8。
{System.Runtime.InteropServices.COMException (0x80041005): Exception from HRESULT: 0x80041005 ---> MS.Internal.ComAutomation.ComAutomationObjectException: Type mismatch
(Source=SWbemObjectEx)
at MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext)
at MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue)
at MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args)
at MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args)
at System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__4(Object obj, InvokeMemberBinder binder, Object[] args)
at CallSite.Target(Closure , CallSite , Object , UInt32 , String , String[]& )
at CallSite.Target(Closure , CallSite , Object , UInt32 , String , String[]& )
这是我的代码
uint HKEY_LOCAL_MACHINE = 0x80000002;
var locatorService = AutomationFactory.CreateObject("WbemScripting.SWbemLocator");
var wmiService = locatorService.ConnectServer(".", "root\\DEFAULT");
wmiService.Security_.ImpersonationLevel = 3;
wmiService.Security_.AuthenticationLevel = 4;
var objRegistry = wmiService.Get("StdRegProv");
string strRegIdentityCodes = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string[] result = null;
objRegistry.EnumKey(HKEY_LOCAL_MACHINE, strRegIdentityCodes, out result);