internal object GetProperty(string name)
            {
                object pVal = null;

                WbemException.ThrowIfFail(this.wbemObject.Get(name, 0, ref pVal, 0, 0));
                return(pVal);
            }
 int WbemNative.IWbemServices.ExecQueryAsync(string queryLanguage, string query, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink)
 {
     if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null))
     {
         return(-2147217400);
     }
     try
     {
         QueryRegex       regex = new QueryRegex(query);
         ParameterContext parms = new ParameterContext(regex.ClassName, this.wbemServices, wbemContext, wbemSink);
         this.GetProvider(parms.ClassName).EnumInstances(new InstancesContext(parms));
         WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null));
     }
     catch (WbemException exception)
     {
         DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610736), new string[] { exception.ToString() });
         wbemSink.SetStatus(0, exception.ErrorCode, null, null);
         return(exception.ErrorCode);
     }
     catch (Exception exception2)
     {
         DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610736), new string[] { exception2.ToString() });
         wbemSink.SetStatus(0, -2147217407, null, null);
         return(-2147217407);
     }
     finally
     {
         Marshal.ReleaseComObject(wbemSink);
     }
     return(0);
 }
            object IWmiMethodContext.GetParameter(string name)
            {
                object pVal = null;

                WbemException.ThrowIfFail(this.wbemInParms.Get(name, 0, ref pVal, 0, 0));
                return(pVal);
            }
 int WbemNative.IWbemServices.DeleteInstanceAsync(string objectPath, int lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink)
 {
     if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null))
     {
         return(-2147217400);
     }
     try
     {
         ObjectPathRegex  objPathRegex = new ObjectPathRegex(objectPath);
         ParameterContext parms        = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink);
         WbemInstance     wbemInstance = new WbemInstance(parms, objPathRegex);
         if (this.GetProvider(parms.ClassName).DeleteInstance(new InstanceContext(wbemInstance)))
         {
             wbemInstance.Indicate();
         }
         WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null));
     }
     catch (WbemException exception)
     {
         DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610738), new string[] { exception.ToString() });
         wbemSink.SetStatus(0, exception.ErrorCode, null, null);
         return(exception.ErrorCode);
     }
     catch (Exception exception2)
     {
         DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610738), new string[] { exception2.ToString() });
         wbemSink.SetStatus(0, -2147217407, null, null);
         return(-2147217407);
     }
     finally
     {
         Marshal.ReleaseComObject(wbemSink);
     }
     return(0);
 }
 internal void SetProperty(string name, object val)
 {
     if (val != null)
     {
         WbemNative.CIMTYPE cimtype = WbemNative.CIMTYPE.CIM_EMPTY;
         if (val is DateTime)
         {
             val = ((DateTime)val).ToString("yyyyMMddhhmmss.ffffff", CultureInfo.InvariantCulture) + "+000";
         }
         else if (val is TimeSpan)
         {
             TimeSpan span = (TimeSpan)val;
             long     num  = (span.Ticks % 0x3e8L) / 10L;
             val = string.Format(CultureInfo.InvariantCulture, "{0:00000000}{1:00}{2:00}{3:00}.{4:000}{5:000}:000", new object[] { span.Days, span.Hours, span.Minutes, span.Seconds, span.Milliseconds, num });
         }
         else if (val is WbemProvider.InstanceContext)
         {
             WbemProvider.InstanceContext context = (WbemProvider.InstanceContext)val;
             val = context.WbemObject;
         }
         else if (val is Array)
         {
             Array array = (Array)val;
             if ((array.GetLength(0) > 0) && (array.GetValue(0) is WbemProvider.InstanceContext))
             {
                 WbemNative.IWbemClassObject[] objArray = new WbemNative.IWbemClassObject[array.GetLength(0)];
                 for (int i = 0; i < objArray.Length; i++)
                 {
                     objArray[i] = ((WbemProvider.InstanceContext)array.GetValue(i)).WbemObject;
                 }
                 val = objArray;
             }
         }
         else if (val is long)
         {
             val     = ((long)val).ToString(CultureInfo.InvariantCulture);
             cimtype = WbemNative.CIMTYPE.CIM_SINT64;
         }
         int hr = this.wbemObject.Put(name, 0, ref val, (int)cimtype);
         if ((-2147217403 == hr) || (-2147217406 == hr))
         {
             EventLogEventId id;
             if (-2147217403 == hr)
             {
                 id = (EventLogEventId)(-1073610732);
             }
             else
             {
                 id = (EventLogEventId)(-1073610731);
             }
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, id, new string[] { this.className, name, val.GetType().ToString() });
         }
         else
         {
             WbemException.ThrowIfFail(hr);
         }
     }
 }
        int WbemNative.IWbemServices.PutInstanceAsync(
            WbemNative.IWbemClassObject wbemObject,
            Int32 lFlags,
            WbemNative.IWbemContext wbemContext,
            WbemNative.IWbemObjectSink wbemSink
            )
        {
            if (wbemObject == null || wbemContext == null || wbemSink == null || this.wbemServices == null)
            {
                return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER);
            }

            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                try
                {
                    object val   = null;
                    int    type  = 0;
                    int    favor = 0;
                    WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, ref val, ref type, ref favor));
                    string className = (string)val;
                    ServiceModelActivity.Start(activity, SR.GetString(SR.WmiPutInstance, string.IsNullOrEmpty(className) ? string.Empty : className), ActivityType.WmiPutInstance);

                    ParameterContext parms        = new ParameterContext(className, this.wbemServices, wbemContext, wbemSink);
                    WbemInstance     wbemInstance = new WbemInstance(parms, wbemObject);
                    IWmiProvider     wmiProvider  = this.GetProvider(parms.ClassName);
                    if (wmiProvider.PutInstance(new InstanceContext(wbemInstance)))
                    {
                        wbemInstance.Indicate();
                    }

                    WbemException.ThrowIfFail(wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                                                 (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null));
                }
                catch (WbemException e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       e.ErrorCode, null, null);
                    return(e.ErrorCode);
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null);
                    return((int)WbemNative.WbemStatus.WBEM_E_FAILED);
                }
                finally
                {
                    Marshal.ReleaseComObject(wbemSink);
                }
            }
            return((int)WbemNative.WbemStatus.WBEM_S_NO_ERROR);
        }
            internal object GetProperty(string name)
            {
                object val   = null;
                int    type  = 0;
                int    favor = 0;

                WbemException.ThrowIfFail(this.wbemObject.Get(name, 0, ref val, ref type, ref favor));
                return(val);
            }
            object IWmiMethodContext.GetParameter(string name)
            {
                Fx.Assert(null != this.wbemInParms, "");
                object val   = null;
                int    type  = 0;
                int    favor = 0;

                WbemException.ThrowIfFail(this.wbemInParms.Get(name, 0, ref val, ref type, ref favor));
                return(val);
            }
        int WbemNative.IWbemServices.GetObjectAsync(
            string objectPath,
            Int32 flags,
            WbemNative.IWbemContext wbemContext,
            WbemNative.IWbemObjectSink wbemSink)
        {
            if (wbemContext == null || wbemSink == null || this.wbemServices == null)
            {
                return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER);
            }

            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ?
                                                   ServiceModelActivity.CreateActivity(true, SR.GetString(SR.WmiGetObject, string.IsNullOrEmpty(objectPath) ? string.Empty : objectPath), ActivityType.WmiGetObject) : null)
            {
                try
                {
                    ObjectPathRegex  objPathRegex = new ObjectPathRegex(objectPath);
                    ParameterContext parms        = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink);
                    WbemInstance     wbemInstance = new WbemInstance(parms, objPathRegex);
                    IWmiProvider     wmiProvider  = this.GetProvider(parms.ClassName);
                    if (wmiProvider.GetInstance(new InstanceContext(wbemInstance)))
                    {
                        wbemInstance.Indicate();
                    }

                    WbemException.ThrowIfFail(wbemSink.SetStatus(
                                                  (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                                  (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR,
                                                  null,
                                                  null));
                }
                catch (WbemException e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiGetObjectFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       e.ErrorCode, null, null);
                    return(e.ErrorCode);
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiGetObjectFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null);
                    return((int)WbemNative.WbemStatus.WBEM_E_FAILED);
                }
                finally
                {
                    Marshal.ReleaseComObject(wbemSink);
                }
            }
            return((int)WbemNative.WbemStatus.WBEM_S_NO_ERROR);
        }
 internal MethodContext(WbemProvider.ParameterContext parms, string methodName, WbemNative.IWbemClassObject wbemInParms, WbemProvider.WbemInstance wbemInstance)
 {
     this.parms       = parms;
     this.methodName  = methodName;
     this.wbemInParms = wbemInParms;
     this.instance    = new WbemProvider.InstanceContext(wbemInstance);
     WbemNative.IWbemClassObject ppObject = null;
     WbemException.ThrowIfFail(parms.WbemServices.GetObject(parms.ClassName, 0, parms.WbemContext, ref ppObject, IntPtr.Zero));
     WbemNative.IWbemClassObject ppOutSignature = null;
     WbemException.ThrowIfFail(ppObject.GetMethod(methodName, 0, IntPtr.Zero, out ppOutSignature));
     WbemException.ThrowIfFail(ppOutSignature.SpawnInstance(0, out this.wbemOutParms));
 }
        int WbemNative.IWbemServices.CreateInstanceEnumAsync(
            string className,
            Int32 flags,
            WbemNative.IWbemContext wbemContext,
            WbemNative.IWbemObjectSink wbemSink)
        {
            if (wbemContext == null || wbemSink == null || this.wbemServices == null)
            {
                return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER);
            }

            try
            {
                ParameterContext parms       = new ParameterContext(className, this.wbemServices, wbemContext, wbemSink);
                IWmiProvider     wmiProvider = this.GetProvider(parms.ClassName);
                wmiProvider.EnumInstances(new InstancesContext(parms));

                WbemException.ThrowIfFail(wbemSink.SetStatus(
                                              (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                              (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR,
                                              null,
                                              null));
            }
            catch (WbemException e)
            {
                wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                   e.ErrorCode, null, null);
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.WmiCreateInstanceFailed,
                                                    className,
                                                    e.ToString());
                return(e.ErrorCode);
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.WmiCreateInstanceFailed,
                                                    className,
                                                    e.ToString());
                wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                   (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null);
                return((int)WbemNative.WbemStatus.WBEM_E_FAILED);
            }
            finally
            {
                Marshal.ReleaseComObject(wbemSink);
            }
            return((int)WbemNative.WbemStatus.WBEM_S_NO_ERROR);
        }
 internal WbemInstance(WbemProvider.ParameterContext parms, string className)
 {
     this.parms = parms;
     if (string.IsNullOrEmpty(className))
     {
         className = parms.ClassName;
     }
     this.className = className;
     WbemNative.IWbemClassObject ppObject = null;
     WbemException.ThrowIfFail(parms.WbemServices.GetObject(className, 0, parms.WbemContext, ref ppObject, IntPtr.Zero));
     if (ppObject != null)
     {
         WbemException.ThrowIfFail(ppObject.SpawnInstance(0, out this.wbemObject));
     }
 }
            internal WbemInstance(ParameterContext parms, string className)
            {
                this.parms = parms;
                if (String.IsNullOrEmpty(className))
                {
                    className = parms.ClassName;
                }
                this.className = className;
                WbemNative.IWbemClassObject tempObj = null;
                WbemException.ThrowIfFail(
                    parms.WbemServices.GetObject(className, 0, parms.WbemContext, ref tempObj, IntPtr.Zero)
                    );


                if (null != tempObj)
                {
                    WbemException.ThrowIfFail(tempObj.SpawnInstance(0, out this.wbemObject));
                }
            }
 int WbemNative.IWbemServices.PutInstanceAsync(WbemNative.IWbemClassObject wbemObject, int lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink)
 {
     if (((wbemObject == null) || (wbemContext == null)) || ((wbemSink == null) || (this.wbemServices == null)))
     {
         return(-2147217400);
     }
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         try
         {
             WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, null, 0, 0));
             string str = (string)pVal;
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("WmiPutInstance", new object[] { string.IsNullOrEmpty(str) ? string.Empty : str }), ActivityType.WmiPutInstance);
             ParameterContext parms        = new ParameterContext(str, this.wbemServices, wbemContext, wbemSink);
             WbemInstance     wbemInstance = new WbemInstance(parms, wbemObject);
             if (this.GetProvider(parms.ClassName).PutInstance(new InstanceContext(wbemInstance)))
             {
                 wbemInstance.Indicate();
             }
             WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null));
         }
         catch (WbemException exception)
         {
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610739), new string[] { TraceUtility.CreateSourceString(this), exception.ToString() });
             wbemSink.SetStatus(0, exception.ErrorCode, null, null);
             return(exception.ErrorCode);
         }
         catch (Exception exception2)
         {
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610739), new string[] { TraceUtility.CreateSourceString(this), exception2.ToString() });
             wbemSink.SetStatus(0, -2147217407, null, null);
             return(-2147217407);
         }
         finally
         {
             Marshal.ReleaseComObject(wbemSink);
         }
     }
     return(0);
 }
 int WbemNative.IWbemServices.GetObjectAsync(string objectPath, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink)
 {
     if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null))
     {
         return(-2147217400);
     }
     using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateActivity(true, System.ServiceModel.SR.GetString("WmiGetObject", new object[] { string.IsNullOrEmpty(objectPath) ? string.Empty : objectPath }), ActivityType.WmiGetObject) : null)
     {
         try
         {
             ObjectPathRegex  objPathRegex = new ObjectPathRegex(objectPath);
             ParameterContext parms        = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink);
             WbemInstance     wbemInstance = new WbemInstance(parms, objPathRegex);
             if (this.GetProvider(parms.ClassName).GetInstance(new InstanceContext(wbemInstance)))
             {
                 wbemInstance.Indicate();
             }
             WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null));
         }
         catch (WbemException exception)
         {
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610740), new string[] { TraceUtility.CreateSourceString(this), exception.ToString() });
             wbemSink.SetStatus(0, exception.ErrorCode, null, null);
             return(exception.ErrorCode);
         }
         catch (Exception exception2)
         {
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610740), new string[] { TraceUtility.CreateSourceString(this), exception2.ToString() });
             wbemSink.SetStatus(0, -2147217407, null, null);
             return(-2147217407);
         }
         finally
         {
             Marshal.ReleaseComObject(wbemSink);
         }
     }
     return(0);
 }
        int WbemNative.IWbemServices.ExecMethodAsync(string objectPath, string methodName, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemClassObject wbemInParams, WbemNative.IWbemObjectSink wbemSink)
        {
            if (((wbemContext == null) || (wbemInParams == null)) || ((wbemSink == null) || (this.wbemServices == null)))
            {
                return(-2147217400);
            }
            int hResult = 0;

            try
            {
                ObjectPathRegex  objPathRegex = new ObjectPathRegex(objectPath);
                ParameterContext parms        = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink);
                WbemInstance     wbemInstance = new WbemInstance(parms, objPathRegex);
                MethodContext    method       = new MethodContext(parms, methodName, wbemInParams, wbemInstance);
                if (!this.GetProvider(parms.ClassName).InvokeMethod(method))
                {
                    hResult = -2147217406;
                }
                WbemException.ThrowIfFail(wbemSink.SetStatus(0, hResult, null, null));
            }
            catch (WbemException exception)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610735), new string[] { exception.ToString() });
                hResult = exception.ErrorCode;
                wbemSink.SetStatus(0, hResult, null, null);
            }
            catch (Exception exception2)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610735), new string[] { exception2.ToString() });
                hResult = -2147217407;
                wbemSink.SetStatus(0, hResult, null, null);
            }
            finally
            {
                Marshal.ReleaseComObject(wbemSink);
            }
            return(hResult);
        }
            internal void SetProperty(string name, object val)
            {
                Fx.Assert(null != this.wbemObject, name + " may not be available to WMI");
                if (null != val)
                {
                    WbemNative.CIMTYPE type = 0;
                    if (val is DateTime)
                    {
                        val = ((DateTime)val).ToString("yyyyMMddhhmmss.ffffff", CultureInfo.InvariantCulture) + "+000";
                    }
                    else if (val is TimeSpan)
                    {
                        TimeSpan ts           = (TimeSpan)val;
                        long     microSeconds = (ts.Ticks % 1000) / 10;
                        val = string.Format(CultureInfo.InvariantCulture, "{0:00000000}{1:00}{2:00}{3:00}.{4:000}{5:000}:000",
                                            new object[] { ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds, microSeconds });
                    }
                    else if (val is InstanceContext)
                    {
                        InstanceContext inst = (InstanceContext)val;
                        val = inst.WbemObject;
                    }
                    else if (val is Array)
                    {
                        Array objs = (Array)val;
                        if (objs.GetLength(0) > 0 && objs.GetValue(0) is InstanceContext)
                        {
                            WbemNative.IWbemClassObject[] insts = new WbemNative.IWbemClassObject[objs.GetLength(0)];
                            for (int i = 0; i < insts.Length; ++i)
                            {
                                insts[i] = ((InstanceContext)objs.GetValue(i)).WbemObject;
                            }
                            val = insts;
                        }
                    }
                    else if (val is Int64)
                    {
                        val  = ((Int64)val).ToString(CultureInfo.InvariantCulture);
                        type = WbemNative.CIMTYPE.CIM_SINT64;
                    }

                    int hResult = this.wbemObject.Put(name, 0, ref val, (int)type);
                    if ((int)WbemNative.WbemStatus.WBEM_E_TYPE_MISMATCH == hResult || (int)WbemNative.WbemStatus.WBEM_E_NOT_FOUND == hResult)
                    {
                        //This would be most likely a product bug (somebody changed type without updating MOF), improper installation or tampering with MOF
                        System.Runtime.Diagnostics.EventLogEventId eventId;
                        if ((int)WbemNative.WbemStatus.WBEM_E_TYPE_MISMATCH == hResult)
                        {
                            eventId = System.Runtime.Diagnostics.EventLogEventId.WmiAdminTypeMismatch;
                        }
                        else
                        {
                            eventId = System.Runtime.Diagnostics.EventLogEventId.WmiPropertyMissing;
                        }
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                            (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi,
                                                            (uint)eventId,
                                                            this.className,
                                                            name,
                                                            val.GetType().ToString());
                    }
                    else
                    {
                        WbemException.ThrowIfFail(hResult);
                    }
                }
            }
 void IWmiMethodContext.SetParameter(string name, object value)
 {
     WbemException.ThrowIfFail(this.wbemOutParms.Put(name, 0, ref value, 0));
 }
 void IWmiInstances.AddInstance(IWmiInstance inst)
 {
     WbemException.ThrowIfFail(this.parms.WbemSink.Indicate(1,
                                                            new WbemNative.IWbemClassObject[] { ((InstanceContext)inst).WbemObject }));
 }
        int WbemNative.IWbemServices.ExecMethodAsync(
            string objectPath,
            string methodName,
            Int32 flags,
            WbemNative.IWbemContext wbemContext,
            WbemNative.IWbemClassObject wbemInParams,
            WbemNative.IWbemObjectSink wbemSink)
        {
            if (wbemContext == null || wbemInParams == null || wbemSink == null || this.wbemServices == null)
            {
                return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER);
            }

            int result = (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR;

            try
            {
                ObjectPathRegex  objPathRegex = new ObjectPathRegex(objectPath);
                ParameterContext parms        = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink);
                WbemInstance     wbemInstance = new WbemInstance(parms, objPathRegex);

                MethodContext methodContext = new MethodContext(parms, methodName, wbemInParams, wbemInstance);
                IWmiProvider  wmiProvider   = this.GetProvider(parms.ClassName);
                if (!wmiProvider.InvokeMethod(methodContext))
                {
                    result = (int)WbemNative.WbemStatus.WBEM_E_NOT_FOUND;
                }

                WbemException.ThrowIfFail(wbemSink.SetStatus(
                                              (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                              (int)result,
                                              null,
                                              null));
            }
            catch (WbemException e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecMethodFailed,
                                                    e.ToString());
                result = e.ErrorCode;
                wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                   result, null, null);
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecMethodFailed,
                                                    e.ToString());
                result = (int)WbemNative.WbemStatus.WBEM_E_FAILED;
                wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                   (int)result, null, null);
            }
            finally
            {
                Marshal.ReleaseComObject(wbemSink);
            }
            return(result);
        }
 internal void Indicate()
 {
     WbemException.ThrowIfFail(this.parms.WbemSink.Indicate(1,
                                                            new WbemNative.IWbemClassObject[] { this.wbemObject }));
 }