Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight 5受信任的应用程序EnumKeys StdRegProv不断获得类型不匹配_C#_Silverlight_Com_Registry_Wmi - Fatal编程技术网

C# Silverlight 5受信任的应用程序EnumKeys StdRegProv不断获得类型不匹配

C# Silverlight 5受信任的应用程序EnumKeys StdRegProv不断获得类型不匹配,c#,silverlight,com,registry,wmi,C#,Silverlight,Com,Registry,Wmi,我在Silverlight 5中有一个已签名、受信任的应用程序(并且知道它工作正常,并且启用了AutomationFactory)。然而,无论我做什么,当我试图查询注册表时,我都会得到一个类型不匹配的COM异常,这是没有帮助的。Windows7IE8 {System.Runtime.InteropServices.COMException (0x80041005): Exception from HRESULT: 0x80041005 ---> MS.Internal.ComAutomat

我在Silverlight 5中有一个已签名、受信任的应用程序(并且知道它工作正常,并且启用了AutomationFactory)。然而,无论我做什么,当我试图查询注册表时,我都会得到一个类型不匹配的COM异常,这是没有帮助的。Windows7IE8

{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[]& )

我认为你需要做两个改变:

1) 更改:

致:

避免类型不匹配错误,以及

2) 更改:

致:


为了避免即将出现的“System.InvalidCastException:无法将“System.object[]”类型的对象强制转换为“System.String[]”类型“

哇,就是这样!你怎么知道的?HKEY_LOCAL_机器的MSDN文档一定是错误的?如果我看这里,它说是一个单位。
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);
uint HKEY_LOCAL_MACHINE = 0x80000002;
int HKEY_LOCAL_MACHINE = unchecked((int)0x80000002);
string[] result = null;
object[] result = null;